zoukankan      html  css  js  c++  java
  • 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());
                }
  • 相关阅读:
    7.15 更改累计和中的值
    7.10 计算中间值
    7.11 求总和的百分比
    7.9 计算模式
    7.8 计算累计差
    7.4 求一个表的行数
    7.6 生成累计和
    7.7 生成累积乘积
    7.2 求某列中的最小、最大值
    7.3 对某列的值求和
  • 原文地址:https://www.cnblogs.com/zytr/p/14752585.html
Copyright © 2011-2022 走看看