Reputation: 3506
How would I make a datatype similar to Dictionary where I could have something like:
Dictionary<ClassObject1, List<ClassObject2>> stuff;
Basically, I have ClassOject1
with an unknown number of objects of type ClassObject2
that belong to ClassObject1
. Would I just use type dynamic
or something?
Edit: Trying the following code:
Dictionary<VisitorInfoCookie, List<VisitorInfoCookieValue>> stuff = new List<VisitorInfoCookieValue>>();
causes the compiler to say A new expression requires (), [], or {} after type
with an angry red squiggly under ()
Upvotes: 1
Views: 21
Reputation: 19159
you are creating dictionary.your code should be like.
Dictionary<VisitorInfoCookie, List<VisitorInfoCookieValue>> stuff = new Dictionary<VisitorInfoCookie, List<VisitorInfoCookieValue>>();
if you want to add items to dictionary you can directly do this.
Dictionary<VisitorInfoCookie, List<VisitorInfoCookieValue>> stuff = new Dictionary<VisitorInfoCookie, List<VisitorInfoCookieValue>>
{
{visitorInfoCookie1 , visitorInfoCookieValues1},
{visitorInfoCookie2 , visitorInfoCookieValues2},
//...
};
Upvotes: 1