c# - Initializing a dictionary with anonymous objects -
I'm trying to do the following.
Private Stable Dictionary & lt; Int, object & gt; MAPS = New Dictionary & lt; Int, object & gt; {{1, new {1, 2, 3}}};
It does not work as I expect, so I am pretty sure the issue is that I am using anonymous items. It is believed that I do not want to create a new type for my things and still want to keep all the mapping in the same dictionary, what should I do?
I have seen but now is a little date, so I am hoping that there is something new for this in the structure.
Try it if you want an array of value to int
s in the form of.
Private Stable Dictionary & lt; Int, object & gt; MAPS = New Dictionary & lt; Int, object & gt; {{1, new [] {1, 2, 3}}};
Or if you want an unknown class
private static dictionary & lt; Int, object & gt; MAPS = New Dictionary & lt; Int, object & gt; {{1, new {a = 1, b = 2, c = 3}}};
or better yet do not use object
int <]
or list
or declare a class or structure if you need a specific value, possibly int
for collection of Tuple & lt; Int, int, int & gt; Use
if you need only 3 int
s for each value but, generally try to avoid the need to insert it from object
needed.
Comments
Post a Comment