Exemple #1
0
        //Main_7_1_1
        ////�����ھֲ�������ʹ��readonly
        //public void InlineFunction()
        //{
        //    readonly string myName = "Wang";
        //}
        public static void Main()
        {
            //���ʾ�̬��Ա
            Console.WriteLine(ConstAndReadonly.NAME);
            Console.WriteLine(ConstAndReadonly.PASSWORD);

            //���ʷǾ�̬��Ա
            ConstAndReadonly cr = new ConstAndReadonly();
            Console.WriteLine(cr.AGE);
            Console.WriteLine(cr.SEX);
            ConstAndReadonly cr2 = new ConstAndReadonly(27, "Man");
            Console.WriteLine(cr2.AGE);
            Console.WriteLine(cr2.SEX);

            //�ֲ�����
            cr.InlineConst();
        }
Exemple #2
0
        ////不能在局部变量中使用readonly
        //public void InlineFunction()
        //{
        //    readonly string myName = "Wang";
        //}

        public static void Main()//Main_7_1_1
        {
            //访问静态成员
            Console.WriteLine(ConstAndReadonly.NAME);
            Console.WriteLine(ConstAndReadonly.PASSWORD);

            //访问非静态成员
            ConstAndReadonly cr = new ConstAndReadonly();

            Console.WriteLine(cr.AGE);
            Console.WriteLine(cr.SEX);
            ConstAndReadonly cr2 = new ConstAndReadonly(27, "Man");

            Console.WriteLine(cr2.AGE);
            Console.WriteLine(cr2.SEX);

            //局部常量
            cr.InlineConst();
        }