泛型集合List Dictionary

来源:互联网 发布:网络钢琴家教 编辑:程序博客网 时间:2024/05/14 05:30
List<T>
 ArrayList的所有方法
 Sort(); 分类排序
 Max(); 最大
 Min();最小
 Sum();求和
 avatage();  平均   T,K,V就像是锁,锁住集合中只能存放某种                    特点的类型
                    泛型集合可以镜像foreach遍历,是因为他                    们都实现了IEnumerable都有                                 GetEnumberator()方法   
 List<int> list=new List<int>(); 通过泛型可以限制集合中存                                   放的数据的类型 
 Dictionary<K,V> <键,值>
 Dictionary<string,string>dict=new Dictionary<string,string>
  dict.ContainsKey("zl") 返回bool类型
 Console.WriteLine(dict["zl"]) 
 Dictionary<string,Person>dict=new Dictionary<string,Person>
 //值为类,,
 Person p1 =new Person()
 {}
 遍历
 /1遍历键 
 foreach(string item in dict.Keys)
 {Console.WriteLine(item)}
 /2遍历值
 foreach(Person item in dict.Values)
 {Console.WriteLine(item)}
 /3键和值同时遍历
 foreach(KeyValuePair<string,Person>kv in dict)
 {Console.WriteLine("键:{0} 值:{1}",kv.Key,kv.Values)}
 DictionaryEntry 包含键和值得类型。
 用foreach遍历hash集合时用到
 在里边用var定义 原因是 他是弱类型 在你还不知道你定义的是什么类型时用var 让系统判断是什么类型。。。
 
 
 
原创粉丝点击