为什么80%的码农都做不了架构师?>>>   

System.Collections.Generic.Dictionary<>;       //键/值对集合
System.Collections.Generic.KeyValuePair<>;     //键/值对结构, 作为 Dictionary<> 的一个元素存在
System.Collections.Generic.SortedDictionary<>; //相当于 Key 能自动排序 Dictionary<>
System.Collections.Generic.SortedList<>;       //和 SortedDictionary<> 功能相似, 但内部算法不同, 其 Keys、Values 可通过索引访问System.Collections.Generic.HashSet<>;   //无序、无重复的元素集合
System.Collections.Generic.SortedSet<>; //相当于能自动排序的 HashSet<>
System.Collections.Generic.List<>;      //相当于泛型的 ArrayList, 元素可重复、可排序、可插入、可索引访问System.Collections.Generic.Queue<>; //队列, 先进先出
System.Collections.Generic.Stack<>; //堆栈, 后进先出System.Collections.Generic.LinkedList<>;     //双向链表
System.Collections.Generic.LinkedListNode<>; //LinkedList<> 的节点System.Collections.Generic.SynchronizedCollection<>;         //线程安全的集合
System.Collections.Generic.SynchronizedReadOnlyCollection<>; //线程安全的只读集合
System.Collections.Generic.SynchronizedKeyedCollection<>;    //线程安全的键/值集合


Dictionary<>、KeyValuePair<>:


protected void Button1_Click(object sender, EventArgs e)
{Dictionary<string, int> dict = new Dictionary<string, int>();dict.Add("K1", 123);dict["K2"] = 456;dict.Add("K3", 789);string str = "";foreach (KeyValuePair<string, int> k in dict){str += string.Format("{0}-{1}; ", k.Key, k.Value); //K1-123; K2-456; K3-789; }TextBox1.Text = str;
}


SortedDictionary<>:


protected void Button1_Click(object sender, EventArgs e)
{SortedDictionary<string, int> dict = new SortedDictionary<string, int>();dict.Add("K3", 333);dict["K1"] = 111;dict.Add("K2", 222);SortedDictionary<string, int>.KeyCollection ks = dict.Keys;SortedDictionary<string, int>.ValueCollection vs = dict.Values;string s1, s2, s3;s1 = s2 = s3 = "";foreach (KeyValuePair<string, int> k in dict){s1 += string.Format("{0}-{1}; ", k.Key, k.Value); //K1-111; K2-222; K3-333;}foreach (string s in ks) { s2 += s + "; "; }          //K1; K2; K3;foreach (int n in vs) { s3 += n.ToString() + "; "; }  //111; 222; 333; TextBox1.Text = s1 + "\n" + s2 + "\n" + s3;
}


SortedList<>:


protected void Button1_Click(object sender, EventArgs e)
{SortedList<string, int> dict = new SortedList<string, int>();dict.Add("K3", 333);dict["K1"] = 111;dict.Add("K2", 222);string s1, s2, s3;s1 = s2 = s3 = "";foreach (KeyValuePair<string, int> k in dict){s1 += string.Format("{0}-{1}; ", k.Key, k.Value); //K1-111; K2-222; K3-333;}s2 = dict.Keys[0];              //K1s3 = dict.Values[0].ToString(); //111TextBox1.Text = s1 + "\n" + s2 + "\n" + s3;
}


HashSet<>、SortedSet<>:


protected void Button1_Click(object sender, EventArgs e)
{HashSet<string> hs = new HashSet<string>();hs.Add("ccc");hs.Add("bbb");hs.Add("aaa");SortedSet<string> ss = new SortedSet<string>();ss.Add("ccc");ss.Add("bbb");ss.Add("aaa");string s1 = "", s2 = "";foreach (string s in hs) { s1 += s + " "; } //ccc bbb aaa foreach (string s in ss) { s2 += s + " "; } //aaa bbb ccc TextBox1.Text = s1 + "\n" + s2;
}


List<>:


protected void Button1_Click(object sender, EventArgs e)
{List<int> list = new List<int>();list.Add(11);list.Add(22);list.Insert(0, 33);string s1, s2 = "", s3, s4 = "";s1 = list[0].ToString(); //33for (int i = 0; i < list.Count; i++) { s2 += list[i].ToString() + " "; } //33 11 22list.Sort();s3 = list[0].ToString(); //11foreach (int n in list) { s4 += n.ToString() + " "; } //11 22 33 TextBox1.Text = s1 + "\n" + s2 + "\n" + s3 + "\n" + s4;
}


LinkedList<>、LinkedListNode<>:


protected void Button1_Click(object sender, EventArgs e)
{LinkedList<string> list = new LinkedList<string>();list.AddFirst("aaa");list.AddLast("bbb");list.AddFirst("ccc");list.AddAfter(list.First, "ddd");list.AddBefore(list.Last, "eee");string s1 = "", s2 = "", s3 = "", s4 = "", s5 = "";foreach (string s in list) { s1 += s + " "; } //ccc ddd aaa eee bbb LinkedListNode<string> node = list.First;s2 = node.Value.ToString();         //cccnode = node.Next;s3 = node.Value.ToString();         //dddnode = list.Last.Previous.Previous;s4 = node.Value.ToString();         //aaalist.Remove("eee");list.RemoveFirst();list.RemoveLast();node = list.First;while (node != null){s5 += node.Value.ToString() + " "; //ddd aaa node = node.Next;}TextBox1.Text = s1 + "\n" + s2 + "\n" + s3 + "\n" + s4 + "\n" + s5;
}

转载于:https://my.oschina.net/hermer/blog/320253

学用 ASP.Net 之 System.Collections.Generic 下的容器类相关推荐

  1. 学用 ASP.Net 之 System.Collections.Specialized.CollectionsUtil 类

    通过 CollectionsUtil 创建或包装的 "键/值对" 类(实现 IDictionary 的), 可以忽略 Key 的大小写. 主要成员: /* 静态方法 */ Coll ...

  2. 学用 ASP.Net 之 System.Collections.Hashtable 类与 DictionaryEntry 结构

    DictionaryEntry 是包含 Key / Value 一对值的简单结构; Hashtable(哈希表)是一组 Key / Value 的集合, 准确地讲是一组 DictionaryEntry ...

  3. 类型实现《程序员的第一年》--------------C#中System.Collections.Generic.SortedDictionary 的使用...

    在改章节中,我们主要介绍类型实现的内容,自我感觉有个不错的建议和大家分享下 SortedDictionary<TKey,TValue> 类型参数 TKey 字典中的键的类型. TValue ...

  4. Resx 文件无效。未能加载 .RESX 文件中使用的类型 System.Collections.Generic.List`1请确保已在项目中添加了必需的引用。

    在C#程序编写过程中,会遇到:Resx 文件无效.未能加载 .RESX 文件中使用的类型 System.Collections.Generic.List1`请确保已在项目中添加了必需的引用. 主要原因 ...

  5. Unity3d:Unknown type 'System.Collections.Generic.CollectionDebuggerView'1

    问题描述:如图,在调试状态下说:Unknown type 'System.Collections.Generic.CollectionDebuggerView'1 <ignore_js_op&g ...

  6. 钉钉审批回调 获取单个审批实例详情  遇见System.Collections.Generic.List`1[DRMS.DingTalk.FormRowValue+ExtendValue] 错误

    /processinstance/get 获取单个审批实例详情 接口 错误:Error converting value "[{"emplId":"111111 ...

  7. [corefx注释说]-System.Collections.Generic.StackT

    对C#里边的基础类库有充分的好奇心,所以就心血来潮写一下,这个就不定期更新了,想什么时候写就什么时候写好了.这里弱弱的吐槽一下CSDN的博客.为了以防万一,会在我其他的博客做一下备份. 废话不多说 切 ...

  8. Multiple constructors accepting all given System.Collections.Generic.List

    出现上述错误的原因是给的List未定义或未找到 在学习ASP.Net Core Razor Page时,使用了ViewModel,按照mvc的逻辑,更改了View的model类型, 系统报上述错误,是 ...

  9. 学用 ASP.Net 之 System.Char 结构

    成员: /* 常数字段 */MaxValue //65535MinValue //0/* 静态方法 */Char.ConvertFromUtf32() //转 Unicode 值到字符串Char.Co ...

  10. .Net Framework System.Collections 集合类

    本文内容 集合类 性能 最近复习了一下集合,C# 关于集合的类蛮多,但我除了 List 那几个经常用之外,其他的用得还真不多(只在小范围使用),但其实,每个集合类都各有自己适用的场景,功能也很强大.尤 ...

最新文章

  1. 初识Tcl(五):Tcl 循环
  2. 添加打印机还显示脱机_打印机总是显示脱机无法打印的解决办法
  3. 企业网络推广之中如何对网页设计提出新的色彩搭配原理?
  4. 动态代理-JDK_proxycglib
  5. appium 移动端自动化测试工具(4)
  6. Python--粒子滤波定位案例程序
  7. 一个 SAP 开发工程师十余年的技术写作之路回顾
  8. IDEA导入MySQL的jdbc驱动出现“java.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver”
  9. 吴恩达深度学习编程作业汇总
  10. redis常用操作-键的生存时间
  11. vue让元素固定_vue 监听dom元素的滚动事件 实现某元素吸顶或者固定位置显示
  12. MySQL 基础操作
  13. 【物流推荐】HEGERLS堆垛机—自动化立体仓库中最重要的起重运输设备
  14. 当你一个人走过你们曾经走过的大街小巷,你会有何感受?
  15. python md5解密方法与技巧_python ---- 爬取 md5解密结果 的小脚本
  16. 2020蓝桥杯省赛B组
  17. 自用房屋租住管理系统
  18. Python之kafka消息队列操作入门
  19. 如何系统地做产品规划(极简版)
  20. java 多线程 卖票_编写一个Java 多线程程序,完成三个售票窗口同时出售20张票(如下图所示);...

热门文章

  1. C# 删除DataTable中的空行
  2. 复杂的三元转化为if() eles()
  3. Git从远程主分支切换出一个开发分支
  4. Layer success 层弹出后的成功回调方法
  5. 近来很多人通过这个博文加关注,为何?
  6. 文字处理技术:新布局思路验证成功
  7. fatal error: alsa/asoundlib.h: 没有那个文件或目录
  8. Eclipse无法DEBUG
  9. 以围棋来说,人工智能程序跟通常程序差异在哪里
  10. 安卓一个奇怪的LOG:ColorDrawable.setColor