文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>C# 泛型相关.

C# 泛型相关.

时间:2010-09-24  来源:胖子黎

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Collections.Specialized;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            ArrayList myList = new ArrayList(20);
            myList.Add(20);  //装箱操作.

            myList.Add(202);

            int i1 = (int)myList[0];  //拆箱操作

            foreach (int item in myList)
            { 
                Console.WriteLine(item);  //这个程序是关于ArrayList的.
            }

            List<int> myListT = new List<int>(10);
            myListT.Add(412);    //不会装箱操作

            int i2 = myListT[0];   //不会拆箱.

            foreach (int item in myListT)
            {
                Console.WriteLine(item);
            }
            //值得注意的是,如果在附值的时候有不同类型进去,但是用foreach循环的时候就会报错,
            //用泛型可以避免这种情况。在编译的时候就会报错.
           

          

        }
        public class MyOK  //下面是泛型的几个例子
        {
            public delegate void EventHandler<TEventArgs>(object sender, TEventArgs e);

            public delegate TOutput Converter<TOutput, TIntput>(TIntput from);

           
        }
        public class SortedList<Tkey, Tvalue>
        {
 
        }

    }

}

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载