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

 

相关文章:

  • 2022-02-28
  • 2022-01-26
  • 2021-10-29
  • 2022-01-22
  • 2021-07-26
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-24
  • 2021-12-19
  • 2021-11-29
  • 2021-10-16
  • 2021-11-17
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案