System.Collections.Generic的各容器类的用法

演示System.Collections.Generic的各容器类的用法.包括:Dictionary,KeyValuePair,SortedDic tionary,SortedList,HashSet,SortedSet,List,Queue,Stack等 1 System.Collections.Generic.Dictionary<>; //键/值对...
摘要由CSDN通过智能技术生成

演示System.Collections.Generic的各容器类的用法.

包括:Dictionary,KeyValuePair,SortedDic tionary,SortedList,HashSet,SortedSet,List,Queue,Stack等

 

  1 System.Collections.Generic.Dictionary<>;       //键/值对集合
  2 System.Collections.Generic.KeyValuePair<>;     //键/值对结构, 作为 Dictionary<> 的一个元素存在
  3 System.Collections.Generic.SortedDictionary<>; //相当于 Key 能自动排序 Dictionary<>
  4 System.Collections.Generic.SortedList<>;       //和 SortedDictionary<> 功能相似, 但内部算法不同, 其 Keys、Values 可通过索引访问
  5 
  6 System.Collections.Generic.HashSet<>;   //无序、无重复的元素集合
  7 System.Collections.Generic.SortedSet<>; //相当于能自动排序的 HashSet<>
  8 System.Collections.Generic.List<>;      //相当于泛型的 ArrayList, 元素可重复、可排序、可插入、可索引访问
  9 
 10 System.Collections.Generic.Queue<>; //队列, 先进先出
 11 System.Collections.Generic.Stack<>; //堆栈, 后进先出
 12 
 13 System.Collections.Generic.LinkedList<>;     //双向链表
 14 System.Collections.Generic.LinkedListNode<>; //LinkedList<> 的节点
 15 
 16 System.Collections.Generic.SynchronizedCollection<>;         //线程安全的集合
 17 System.Collections.Generic.SynchronizedReadOnlyCollection<>; //线程安全的只读集合
 18 System.Collections.Generic.SynchronizedKeyedCollection<>;    //线程安全的键/值集合
 19 
 20 Dictionary<>、KeyValuePair<>:
 21 protected void Button1_Click(object sender, EventArgs e)
 22 {
 23     Dictionary<string, int> dict = new Dictionary<string, int>();
 24     dict.Add("K1", 123);
 25     dict["K2"] = 456;
 26     dict.Add("K3", 789);
 27 
 28     string str = "";
 29     foreach (KeyValuePair<string, int> k in dict)
 30     {
 31         str += string.Format(
  • 3
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值