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()
{
DataTypes = new List<string>();
DataTypes.Add("DataInfo");
DataTypes.Add("Maps");
DataTypes.Add("Tilesets");
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>());
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>());
GameData = new Dictionary<string, object>(TempData);
- , , !
, , .
, , , , Value.
, "T" , , , : " " T " "
, ?
-