在Class.cs类里 我想写个string[] 数组 在运行时主程序 初始化它  然后作为全局变量可以调用它  请教 呵呵

解决方案 »

  1.   

    public static string[] a;
      

  2.   

    class Program
    {
      public static string[] a;
      
      static void Main()
      {
        a = new string[] { "abc", "123", "其他", };
      }
    }
      

  3.   

    我的要求是写在 calss1.cs类 里面 可能没说清楚 登录成功后 用数据库首先添充他 以后再调用里面的数据 就不会在读数据库 其长度是不确定的 
      

  4.   

    class Class1
    {
      public static string[] a;
    }class Program
    {  
      static void Main()
      {
        Class1.a = 从数据库中读入;
      }
    }
      

  5.   


        class Class1
        {
            public int[] myArray = new int[100];
            public  int this[int index]
            {
                get
                {
                    if (index < 0 || index >= 100)
                        return 0;
                    else
                        return myArray[index];
                }
                set
                {
                    if (!(index < 0 || index >= 100))
                        myArray[index] = value;
                }
            }  
        }主要是受这个影响 现在还没明白 上面的来龙去脉  看谁能解释下 9楼的是对的 class Class1
    {
      public static string[] a =null;
    }