标签:blog io ar sp for 数据 div on log
今天在云和学院复习了以前的知识,又学习了ArrayList和HashTable
ArrayList实例:
ArrayList arr = new ArrayList(); int i = 123; string str = "宋连城"; float f = 1.23f; decimal d = 2.13m; double dou = 22.16; arr.Add(i); arr.Add(str); arr.Add(f); arr.Add(d); arr.Add(dou); arr.Remove(dou); arr.RemoveAt(2); for (int j = 0; j < arr.Count; j++) { Console.WriteLine(arr[j]); } Console.ReadKey();
HashTable实例:
Hashtable hash = new Hashtable(); string id = "272012321029"; string name = "宋丽"; string id1 = "272012321028"; string name1 = "婷婷"; hash.Add(id,name); hash.Add(id1,name1); foreach (DictionaryEntry item in hash) { Console.WriteLine(item.Key); Console.WriteLine(item.Value); } int[] array = {12,45,23,89 }; foreach (var item in array) { Console.WriteLine(item); } Console.ReadKey();
foreach语法:
List<int> list = new List<int>(); for (int i = 1; i < 100; i++) { list.Add(i); } foreach (var item in list) { Console.WriteLine(item); } Console.ReadKey();
Dictionary
Dictionary <TKey,TValue>
Dictionary实例:
Dictionary<int, string> dic = new Dictionary<int, string>(); dic.Add(1,"范冰冰"); dic.Add(2,"周韦彤"); dic.Add(3,"范玮琪"); dic.Add(4,"蔡国庆"); dic.Add(5, "孙俪"); foreach (var item in dic) { Console.WriteLine(item.Key); Console.WriteLine(item.Value); } Console.ReadKey();
标签:blog io ar sp for 数据 div on log
原文地址:http://www.cnblogs.com/songfang/p/4106635.html