How can I access an array stored in a dictionary?
Hi, I wanted to store some an array in a dictionary but I am having a little trouble understanding how to access it after it's in the dictionary without using a loop.
I have this as my dictionary:
private Dictionary dict = new Dictionary()
{
{"names", new string[] {"Joe","Bob","Billy", "Ned"}},
{"Message","Hello!"}
};
So if I try to get the length of the array for instance, it doesn't work:
Console.WriteLine(dict["names"].Length);
how can I access the properties of the array?
Also how would I access a single item by its index number? something like:
Console.WriteLine(dict["names"][2]);
Still learning C# so any help would be appreciated. Thanks!
Posted Apr 5, 2022, 8:32 PM UTC
013