Why is overriding static method alowed in C#

前端 未结 6 1176
陌清茗
陌清茗 2021-02-06 06:55
protected static new void WhyIsThisValidCode()
{
}

Why are you allowed to override static methods? Nothing but bugs can come from it, it doensn\'t work

6条回答
  •  误落风尘
    2021-02-06 07:15

    for my surprise following code is allowed and compiles without any error on .net Framework 4.5.1, VS 2013.

    class A
    {
        public static void Foo()
        {
        }
    }
    
    class B : A
    {
    
    }
    
    class Program
    {
        static void main(string[] args)
        {
            B.Foo();
        }
    }
    

提交回复
热议问题