in C# I need to keep data in a dictionary object, looks like:
Dictionary<string, Dictionary<string, string>> MyDict =
new Dictionary<string, Dictionary<string, string>>();
Now I realised, that I would need in some cases some other (not dictionary-like) data as value of the main dict.
Is there any kind of Problem or limitation, if I just instance the main dict. as:
Dictionary<string, object> MyDict = new Dictionary<string, object>();
in the object field I could put string, dictionary, whatever..
Thanks in advance,
Best regards, Steven
By using object as the value in your dictionary you will incur some risk and complications:
You should probably rethink your design. But if you really want a the flexibility you could create a new type that would work as the value type. Something like:
Your main dictionary declaration would then look something like:
You could use the ActiveType property or create an enum which would specify the type. You could also have static util functions in the class which could help with returning the right instance and type…