摘要:Dictionary
01
// TKey: Dictionary 索引的型態
02
// TValue: 對應索引值的型態
03
// Dictionary<TKey,TValue> dic = new Dictionary<TKey,TValue>();
04
05 Dictionary<string, string> dic = new Dictionary<string. string>();
06
// assign key & value - method 1:
07
dic.Add("West", "Spare A");
08
// assign key & value - method 2:
09
dic["East"] = "Heart K";
10
11 // 利用foreach取出Dictionary的 Key & Value
12
foreach(KeyValuePair<string, string> pair in dic)
13
{
14
Console.WriteLine("Key: {0}, Value: {1}", pair.Key, pair.Value);
15
}
16
17
// TKey: Dictionary 索引的型態02
// TValue: 對應索引值的型態03
// Dictionary<TKey,TValue> dic = new Dictionary<TKey,TValue>();04

05 Dictionary<string, string> dic = new Dictionary<string. string>();
06
// assign key & value - method 1:07
dic.Add("West", "Spare A");08
// assign key & value - method 2:09
dic["East"] = "Heart K";10

11 // 利用foreach取出Dictionary的 Key & Value
12
foreach(KeyValuePair<string, string> pair in dic)13
{14
Console.WriteLine("Key: {0}, Value: {1}", pair.Key, pair.Value);15
}16

17
