在 C# 中有無類似jAVA map 的資料結構
答案是 >>>> Dictionary
賦值
Dictionary<string, string[]> dic = newDictionary<string, string[]>();
dic.Add("cookie", newstring []{ "Free cookie", "cookie" });
dic.Add("drink", newstring[] { "Free drink", "drink" });
|
取值
foreach(KeyValuePair <int ,string []> item in dic ){
System.Console.WriteLine("key: "+item.key );
System.Console.WriteLine("Value: "+item.value[0] );
}
|
結果:
key: cookie
value: Free cookie
key: drink
value: Free drink
|
Note: 每組key 必須唯一
留言
張貼留言