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: 
You can do that. After retrieving data from the main dictionary, you will have to cast the result to an appropriate type:

```
object obj;
If(mainDict.TryGetValue("key", out obj)) {
    var dict = obj as Dictionary<string, string>>;
    if (dict != null) {
        // work with dict
    } else {
        var value = obj as MyOtherType;
        ....
    }
}

```

But note that this is not type-safe; i.e., the compiler can only partially check the validity of your code regarding the values of type `object`.

---

Alternatively you could try a more object-oriented solution

```
public abstract class MyBaseClass 
{
    public abstract void DoSomething();
}

public class MyDictClass : MyBaseClass
{
    public readonly Dictionary<string, string> Dict = new Dictionary<string, string>();

    public override void DoSomething()
    {
        // So something with Dict
    }
}

public class MyTextClass : MyBaseClass
{
    public string Text { get; set; }

    public override void DoSomething()
    {
        // So something with Text
    }
}

```

Then declare your main dictionary with

```
var mainDict = new Dictionary<string, MyBaseClass>();

mainDict.Add("x", new MyDictClass());
mainDict.Add("y", new MyTextClass());

...

MyBaseClass result = mainDict[key];
result.DoSomething(); // Works for dict and text!

```
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.