C# static member “inheritance” - why does this exist at all?

前端 未结 7 1416
忘掉有多难
忘掉有多难 2020-11-27 19:32

In C#, a superclass\'s static members are \"inherited\" into the subclasses scope. For instance:

class A { public static int M() { return 1; } }
class B : A         


        
7条回答
  •  时光说笑
    2020-11-27 19:56

    I think it's for accessing protected static members of the base class.

    class Base
    {
        protected static void Helper(string s)
        {
           Console.WriteLine(s);
        }
    }
    
    class Subclass : Base
    {
       public void Run()
        {
           Helper("From the subclass");
        }
    }
    

提交回复
热议问题