由于今天在家里,没装VS环境,但是感觉自己对list<t>类似的泛型还不太了解,哪位能给我举个实际调用的例子,简单点的就行,先谢谢各位!

解决方案 »

  1.   

    List<String> lt1=new List<String>();
    List<int> lt2=new List<int>();
    lt1.add("Hello ");
    lt1.add("World!");
    lt2.add(1);
    lt2.add(2);
      

  2.   

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;namespace ConsoleApplication43
    {
        class ren
        {
            private readonly string name;        public string Name
            {
                get { return name; }
            }        private readonly int age;        public int Age
            {
                get { return age; }
            }
            public ren(string newname, int newage)
            {
                name = newname;
                age = newage;
            }    }
        class Program
        {
            static void Main(string[] args)
            {
                List<ren> mylist = new List<ren>();
                mylist.Add(new ren("名字1", 15));
                mylist.Add(new ren("名字3", 56));
                mylist.Add(new ren("名字5", 47));
                Console.WriteLine("第2个人是 {0} ,{1}岁。", mylist[1].Name,mylist[1].Age);
                Console.ReadKey();
            }
        }
    }
      

  3.   

    using System;
    using System.Collections.Generic;class GenericListDemo
    {
        static void Main(string[] args)
        {
            List<int> alInt32 = new List<int>();        foreach (int number in new int[] { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 })
            {
                alInt32.Add(number);
            }
            OutputMethod(alInt32);        List<double> alDouble = new List<double>();        foreach (double number in new double[] { 10.1, 9.2, 8.3, 7.4, 6.5, 5.6, 4.7, 3.8, 2.9, 1.1 })
            {
                alDouble.Add(number);
            }
            OutputMethod(alDouble);
        }    private static void OutputMethod<T>(List<T> al)
        {
            foreach (T temp in al)
            {
                Console.Write(temp + " ");
            }
            Console.WriteLine();
        }
        
    }
      

  4.   

    http://msdn.microsoft.com/zh-cn/library/ms379564(vs.80).aspx