二道Const,readonly 和 override, new的面试题

1. Const 和 readonly

        const int bb = aa * 10;
        const int aa = 10;
        static readonly int cc = dd * 10;
        static readonly int dd = 10;
        static void Main(string[] args)
        {

            Console.WriteLine("aa:{0},bb:{1}, cc:{2},dd:{3}", aa, bb, cc, dd);
        }

结果:aa:10,bb:100,cc:0,dd:10

2.  override 和 new

    public class Father
    {
        public virtual void MethodA(int i)
        {
            Console.WriteLine(i);
        }
        public void MethodB(Father a)
        {
            a.MethodA(1);
            MethodA(5);
        }
    }

    public class Son : Father
    {
        public override void MethodA(int i)
        {
            Console.WriteLine(i+1);
        }
    }


        static void Main(string[] args)
        {
            Father a = new Father();
            Son b = new Son();
            a.MethodB(a);//1,5
            a.MethodB(b);//2,5
            b.MethodB(b);//2.6
            b.MethodB(a);//1.6



            Console.Read();
        }

如果 Son 中的 override 改为 new 结果是?
1,5 1,5  1,5  1,5

原文地址:https://www.cnblogs.com/chinabc/p/4350657.html