http://www.cnblogs.com/abatei/archive/2008/02/20/1075760.html

泛型优点:
1,操作中避免强制转换或装箱操作的成本或风险 2,安全高效

实际使用:
1,泛型List<T>的运算速度比ArrayList的快,能用ArrayList的地方都可以用List<T>取代
        List<int> ary = new List<int>();
        for (int i = 0; i < count; i++)
        {
            ary.Add(i);
        }


2,能方便的产生键值对Dictionary<T,T>
        Dictionary<int,string> dict=new Dictionary<int,string>();
        dict.Add(0, "aa"); dict.Add(1, "bb"); dict.Add(2, "cc");
        Response.Write("dict[0]=" + dict[0] + "<br>");
        dict[0] = "我已经修改了";
        Response.Write("dict[0]=" + dict[0] + "<br>");
        dict.Remove(0);

        foreach (KeyValuePair<int, string> kv in dict)
        {
            Response.Write("key="+kv.Key+",value="+kv.Value+"<br>");
        }

3、System.Collections.Specialized.HybridDictionary
集合长度少于10时候效率有优先于System.Collections.Generic.Dictionary<string, object>(length)

相关文章:

  • 2018-11-23
  • 2021-11-25
  • 2021-06-22
  • 2021-11-27
  • 2021-09-21
  • 2020-06-19
猜你喜欢
  • 2021-08-01
  • 2021-08-01
  • 2020-06-08
  • 2021-10-19
  • 2019-07-08
  • 2020-06-16
  • 2018-10-25
相关资源
相似解决方案