//泛型鍵值對集合
Dictionary<int, string> dictionary = new Dictionary<int, string>()
{
{ 1,"打法"},
{ 4,"搜尋"},
};
dictionary.Add(2, "你");
dictionary.Add(5, "哈哈");
dictionary.Add(10, "喜喜");
string valuel = dictionary[2];
Console.WriteLine(valuel);
//索引器賦值
dictionary[3] = "拉拉";
dictionary[2] = "薩頂頂";
Console.WriteLine(dictionary[2]);
foreach (KeyValuePair<int, string> item in dictionary)
{
Console.WriteLine("鍵是{0},值是{1}", item.Key, item.Value);
}
//裝箱:比如將 int string的物件強轉為Object物件
int i = 1;
object p = 1;
//拆箱 將objectg 透過顯示型別轉換為int型別的變數
object o = 1;
int n = (int)o;
//都會產生較大的效能損耗
//arraylist存在不安全型別的裝箱拆箱缺點,所以在C#2.0以後,出現了泛型的概念