示例#1
0
        public static void Main()//Main_3_5_2
        {
            #region 静态方法与非静态方法的调用

            //调用静态方法
            MethodInvoke.StaticMethod();
            //调用实例方法
            MethodInvoke mi = new MethodInvoke();
            mi.InstanceMethod();

            #endregion

            #region callvirt调用引用类型的非虚方法

            //MyRefMethod aRefMethod = new MyRefMethod();
            //aRefMethod = null;
            //aRefMethod.ShowInfo();

            #endregion

            #region call和callvirt比较

            //Father father = new Father();
            //father.DoWork();
            //father.DoWorkByVirtual();

            Father son = new Son();
            son.DoWork();
            son.DoVirtualWork();

            if (son is Father)
            {
                Console.WriteLine("He is right.");
            }

            //Son aSon = new Son();
            //aSon.DoWork();
            //aSon.DoWorkByVirtual();
            Son.DoStaticWork();

            //Grandson.DoWork();
            Father aGrandSon = new Grandson();
            aGrandSon.DoWork();
            aGrandSon.DoVirtualWork();
            aGrandSon.DoVirtualAll();


            Console.Read();

            #endregion
        }
示例#2
0
        //Main_3_5_2
        public static void Main()
        {
            #region ��̬������Ǿ�̬�����ĵ���

            //���þ�̬����
            MethodInvoke.StaticMethod();
            //����ʵ������
            MethodInvoke mi = new MethodInvoke();
            mi.InstanceMethod();

            #endregion

            #region callvirt�����������͵ķ��鷽��

            //MyRefMethod aRefMethod = new MyRefMethod();
            //aRefMethod = null;
            //aRefMethod.ShowInfo();

            #endregion

            #region call��callvirt�Ƚ�

            //Father father = new Father();
            //father.DoWork();
            //father.DoWorkByVirtual();

            Father son = new Son();
            son.DoWork();
            son.DoVirtualWork();

            if (son is Father)
            {
                Console.WriteLine("He is right.");
            }

            //Son aSon = new Son();
            //aSon.DoWork();
            //aSon.DoWorkByVirtual();
            Son.DoStaticWork();

            //Grandson.DoWork();
            Father aGrandSon = new Grandson();
            aGrandSon.DoWork();
            aGrandSon.DoVirtualWork();
            aGrandSon.DoVirtualAll();

            Console.Read();

            #endregion
        }