19、泛型入门

一、泛型简介

  

二、泛型与数组对比的优点

  1、性能快

  2、类型安全性

  3、二进制代码重用

  4、代码的扩展

  5、命名约定

三、几种数组与泛型的对比

//简单数组
            string[] strs = { "aaa", "bbb", "ccc", "ddd" };
            for(int i = 0;i<strs.Length;i++)
            {
                 comboBox1.Items.Add(strs[i]);
            }
  //array申明的数组
            Array strs = new string[] { "aaa", "bbb", "ccc", "ddd" };
            for (int i=0;i<strs.Length;i++)
            {
                comboBox2.Items.Add(strs.GetValue(i));
            }
 //ArrayList数组
            System.Collections.ArrayList all = new System.Collections.ArrayList() { 11, "aa", 33m, "bb" };
            for (int i=0; i < all.Count; i++)
            {
                comboBox3.Items.Add(all[i].ToString());
            }
 //泛型
            List<int> li1 = new List<int>();
            li1.Add(32);
            li1.Add(43);
            List<int> li2 = new List<int> { 1, 2, 4, 5, 6, 7 };
            li2.Add(55);
            for(int i =0;i<li2.Count;i++)
            {
                comboBox4.Items.Add(li2[i].ToString());
            }
原文地址:https://www.cnblogs.com/zytr/p/14752585.html