2014-05-07 168 views
-1

我需要從字典中是這樣的格式獲取數據:從嵌套字典獲取值

private Dictionary<string, Dictionary<string, string>> MyDictionary = new Dictionary<string, Dictionary<string, string>>() 
{ 
    {"HEIGHT", new Dictionary<string,string>(){{"table", "TR_HEIGHT"}, {"prefix", "HEI"}}}, 
    {"WEIGHT", new Dictionary<string,string>(){{"table", "TR_WEIGHT"}, {"prefix", "WIL"}}}, 
    {"LENGTH", new Dictionary<string,string>(){{"table", "TR_LENGTH"}, {"prefix", "LEN"}}}, 
}; 

它是更多鈔票來,如果我插入「高度」我回來的前綴是「HEI」和表「TR_HEIGHT」?

感謝的

+1

如果密鑰是已知的始終存在:'VAR前綴= MyDictionary [ 「HEIGHT」] [ 「前綴」];' –

+0

該代碼不編譯 – Alberto

+0

'是更多鈔票如果我插入「HEIGHT」,我回來的前綴是「HEI」,表格是「TR_HEIGHT」?' 請明確。 – Tarec

回答

2

它是更多鈔票來,如果我插入「高度」我回來前綴「HEI」和 表「TR_HEIGHT」?

Dictionary<string, string> heightAttr = MyDictionary["HEIGHT"]; 
string table = heightAttr["table"]; // TR_HEIGHT 
string prefix = heightAttr["prefix"]; // HEI