比如你可以这样用你的类classObject[i],用这个i下标来访问你的为中一个无素,像数组一样,比哪arraylist就是这样的,只要定义成索引就行了.

解决方案 »

  1.   

    示例
    以下示例说明如何声明私有数组字段、myArray 和索引器。通过使用索引器可直接访问实例 b[i]。另一种使用索引器的方法是将数组声明为 public 成员并直接访问它的成员 myArray[i]。
    // cs_keyword_indexers.cs
    using System;
    class IndexerClass 
    {
       private int [] myArray = new int[100]; 
       public int this [int index]   // Indexer declaration
       {
          get 
          {
             // Check the index limits.
             if (index < 0 || index >= 100)
                return 0;
             else
                return myArray[index];
          }
          set 
          {
             if (!(index < 0 || index >= 100))
                myArray[index] = value;
          }
       }
    }public class MainClass 
    {
       public static void Main() 
       {
          IndexerClass b = new IndexerClass();
          // Call the indexer to initialize the elements #3 and #5.
          b[3] = 256;
          b[5] = 1024;
          for (int i=0; i<=10; i++) 
          {
             Console.WriteLine("Element #{0} = {1}", i, b[i]);
          }
       }
    }
      

  2.   

    谢谢hbxtlhx(下着春雨的天) ,说的很好