I do not have a lot of experience with C#, yet I am used of working with associative arrays in PHP.
I see that in C# the List class and the Array are available, but I would like to associate some string keys.
What is the easiest way to handle this?
Thx!
A for loop can be used to access every element of an array.
There are two ways to loop around the associative array. First, by using the for loop, and then by using the 'foreach' command. Example: In Associative arrays in PHP, the array keys() function is used to find indices with names provided to them, and the count() function is used to count the number of indices.
Associative arrays in C++ C++Server Side ProgrammingProgramming. In c++ programming language, an associative array is a special type of array in which the index value can be of any data type i.e. it can be char, float, string, etc. These associative arrays are also known as maps or dictionaries.
You can use any type with an associative array key or value that you can use with a scalar variable. You cannot nest an associative array within another associative array as a key or value. You can reference an associative array using any tuple that is compatible with the array key signature.
Use the Dictionary class. It should do what you need. Reference is here.
So you can do something like this:
IDictionary<string, int> dict = new Dictionary<string, int>(); dict["red"] = 10; dict["blue"] = 20;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With