首页 > 其他 > 详细

19、泛型入门

时间:2021-05-10 23:02:03      阅读:23      评论:0      收藏:0      [点我收藏+]

一、泛型简介

  技术分享图片

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

  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());
            }

 

19、泛型入门

原文:https://www.cnblogs.com/zytr/p/14752585.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!