Why is overriding static method alowed in C#

前端 未结 6 1177
陌清茗
陌清茗 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:28

    Static methods and fields do not belong to class instances but to class definitions. Static methods do not play part in the virtual dispatching mechanism and are not part of the virtual method table.

    They are just methods and fields on that specific class.

    It may look like the methods and fields are "inherited" because you can do SpecificLogger.Log(), but that is just something to keep you from having to refer to the base class all the time.

    Static methods and fields really are just global methods and fields, just the OO kind.

提交回复
热议问题