Reputation: 7628
I want to make collection like first element in string
and second is list
of object. list object can be either int
/string
. I don't know how to achieve this functionality. Pls help. Following kind of data I need:
Key Value
mon_number {1,4,5}
mon_name {jan,apr,may}
quater_number {1,2}
Upvotes: 0
Views: 333
Reputation: 56697
If Key
is unique, you could use Dictionary<string, List<object>>
:
Dictionary<string, List<object>> dict = new ...;
dict["mon_number"] = new List<object>();
dict["mon_number"].Add(1);
dict["mon_number"].Add(2);
dict["mon_number"].Add(5);
dict["mon_name"] = new List<object>();
dict["mon_name"].Add("jan");
dict["mon_name"].Add("apr");
dict["mon_name"].Add("may");
...
You could also use arrays (if the type of the elements in the list is equals for all entries):
Dictionary<string, object[]> dict = new ...;
dict["mon_number"] = new [] {1, 2, 5 };
dict["mon_name"] = new[] { "jan", "apr", "may" }
Upvotes: 2