C # dictionary using TValue in another dictionary

I am new to C #, and I come from a Ruby background. I still have a lot to learn, and so I ask the following question:

Purpose: 1) I would like to create a dictionary with a string as keys and any type of object that I want as values. Something like that:

Dictionary<string, T>

2) But that is not all. I also want the Master dictionary with a string as keys and the Dictionary described above as values. Something like that:

Dictionary<string, Dictionary<string T>>

I want this to be the case, so I can work as an example below:

MasterDictionary[Dict1].Add( Thing1 )
MasterDictionary[Dict2].Add( Thing2 )

Current code: I am trying to achieve this using the following code

public List<string> DataTypes;
public Dictionary<string, Dictionary<string, object>> TempData;
public Dictionary<string, Dictionary<string, object>> GameData;

public Session()
        {   
            // Create a list of all Data Types.
            DataTypes = new List<string>();
            DataTypes.Add("DataInfo");
            DataTypes.Add("Maps");
            DataTypes.Add("Tilesets");

            // Create and populate TempData dictionary.
            TempData = new Dictionary<string, Dictionary<string, object>>();
            TempData.Add("DataInfo", new Dictionary<string, DataInfo>());
            TempData.Add("Maps", new Dictionary<string, Map>());
            TempData.Add("Tilesets", new Dictionary<string, Tileset>());

            // Create GameData dictionary and copy TempData into it.
            GameData = new Dictionary<string, object>(TempData);
        }

Problem: I get the following errors:

1) The best overloaded method match for 'System.Collections.Generic.Dictionary> .Add (string, System.Collections.Generic.Dictionary)' has some invalid arguments

2) 10 1: 'System.Collections.Generic.Dictionary > ' 'System.Collections.Generic.IDictionary'

TempData.Add("DataInfo", new Dictionary<string, DataInfo>());
TempData.Add("Maps", new Dictionary<string, Map>());
TempData.Add("Tilesets", new Dictionary<string, Tileset>());

// Create GameData dictionary and copy TempData into it.
GameData = new Dictionary<string, object>(TempData);

- , , !

, , . , , , , Value.

, "T" , , , : " " T " "

, ?

-

+5
2

, typedefs . :

public void Session()
{
    // Create a list of all Data Types.
    DataTypes = new List<string>();
    DataTypes.Add("DataInfo");
    DataTypes.Add("Maps"); 
    DataTypes.Add("Tilesets");

    // Create and populate TempData dictionary.
    TempData = new Dictionary<string, Dictionary<string, object>>();
    TempData.Add("DataInfo", new Dictionary<string, object>());
    TempData.Add("Maps", new Dictionary<string, object>());
    TempData.Add("Tilesets", new Dictionary<string, object>());

    // Create GameData dictionary and copy TempData into it.
    GameData = new Dictionary<string, Dictionary<string, object>>(TempData);
}
+1

, ....

, , Ruby, .....

, , , , , , .

, , ...

class GameResources
{
    public Dictionary<string, Map> Maps { get; set;}
    public Dictoinary<string, Tileset> Tileset { get; set; }
}

.. , , ,

+3
source

All Articles