What I want is the ability to store name,object pairs.
Unlike objC c#’s Dictionary requires types. In objC I would use id to mean “any object”.
How would I manage this in c#.
So what I’m looking for is:
Dictionary<String,id>.
Sorry if this is really basic!
Without going into a lot of faffery to talk to multiple strongly typed lists of objects, the simplest way to achieve this is with a
Dictionary<string, object>and to cast out your object type as you need it:There are a few dynamic options here such as
ExpandoObject:http://msdn.microsoft.com/en-us/library/system.dynamic.expandoobject.aspx
If you go the object dictionary approach, pay attention to boxing on value types. Using the dynamic approach won’t have the boxing implications, but will require runtime resolution, so performance again is slightly impacted.
Nothing comes for free, but by and large you shouldn’t see the effects of this minor overhead.