比如想定义一个int类型的int i=10,在其它类中可直接引用i,并且变量价为10,谢谢?

解决方案 »

  1.   

    try..class Test
        {
            public static void Main()
            {
                Console.WriteLine(MyClass.COUNT);
            }
        }
        class MyClass
        {
            public const int COUNT = 10;
        }
      

  2.   

    能否不以在类中定义常量的方式呢?比如可否在主程序中使用类似C++中的define方法,这样,就可任意使用这个常量
      

  3.   

    public static int i = 0;
      

  4.   

    public const int COUNT = 10;
    好一点如果是
    public static int i = 0;
    这个值是可以改变的