I have been learning C# myself for 2 months. Before, I learned PHP and see that it has an array where the index is a string, like this:
$John["age"] = 21;
$John["location"] = "Vietnam";
It is very useful to remember what we set to an array element. I tried to find if C# supports that array type, but I haven't seen any answers, yet.
Does C# have an array like this? If it does, how can I create it?
C# supports any type of object for an index. A baked-in implementation is System.Collections.Generic.Dictionary<T1,T2>
. You can declare one like this:
Dictionary<string, string> myDictionary = new Dictionary<string, string>();
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