C#中应该也有List吧,怎么用啊?谁能给出示例代码?我用数组表示自己建的类,发现不能用下标来赋值啊.

解决方案 »

  1.   

    list很好用,可以把对象add进去.
      

  2.   

    C#中有List<T>泛型,引用System.Collection.General命名空间。
      

  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.   

    IList<可序列化的类> list=new List<可序列化的类>();
      

  5.   

    List <类名称> list=new List <同一个类>();类 Emp = new  类();list.Add(Emp);
     
      

  6.   

    List<数据类型> str=new List<数据类型>str.add(数据1);
    str.add(数据2);
      

  7.   

    大家都说的差不多了呵呵,这就是个动态数组,定义和使用都相当方便List <数据类型> str=new List <数据类型> 
    取值的时候和数组的取值一样,第一个就str[0],用起来比数组要好的多嘿嘿
    不过里面的类型必须是统一的(实际操作中大部分都是同一类型数据)而哈希表它的数据比这个复杂了就,但用起来不如找个爽呵呵
      

  8.   

    我觉得这个跟ArrayList差不多吧