Question: 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

Answer: 
Yes, your dictionary would not be strongly typed anymore - in the first approach you could do something like:

```
string value = myDict["foo"]["bar"];

```

In the second approach this is not possible anymore since you have to cast first:

```
string value = ((Dictionary<string,string>)myDict["foo"])["bar"];

```

It sounds like your problem could be solved with a better design approach. Usually the need to store different kind of objects in the same data structure can be avoided by re-designing the solution - so *why* do you need to do this?

**Edit:**

If you just want to handle `null` values you could just do something like:

```
string value = myDict["foo"] != null ? myDict["foo"]["bar"] : null;

```

Or wrapped in an extension method:

```
public static T GetValue<T>(this Dictionary<T, Dictionary<T,T>> dict, 
                            T key, T subKey) where T: class
{
    T value = dict[key] != null ? dict[key][subKey] : null;
    return value;
}

string value = myDict.GetValue("foo", "bar");

```
Well, your code will be less typesafe and you will need runtime type checks and type casts, but otherwise you can use `object` as a dictionary value type and store any types there.