有一个类A,在窗体Form1中动态实例化这个类
代码片段
  public partial class Form1 : Form
   {
      public static  A a1 = new A();
      public static  A a2 = new A();  public Form1()
      {
        InitializeComponent();
      }
...
   }  
可能要实例化多个A,个数不固定.该怎么做?

解决方案 »

  1.   

    public class Program
        {
            public static AAA[] a;
            static void Main(string[] args)
            {
                a[0] = new AAA();
                a[1] = new AAA();//需要的话可以再加
            }
        }
        class AAA { }
      

  2.   

    System.Collections.Generic.List<A> aList = new System.Collections.Generic.List<A>();or:ArrayList
      

  3.   

    好了,用for循环解决了public static A[] a= new A[10];窗体加载时
     for (int i = 0; i < 10; i++)
                {
                    a[i] = new A();
                }