What's a “static method” in C#?

前端 未结 9 2163
再見小時候
再見小時候 2020-11-22 06:48

What does it mean when you add the static keyword to a method?

public static void doSomething(){
   //Well, do something!
}

Can you add the

9条回答
  •  孤城傲影
    2020-11-22 07:18

    Shortly you can not instantiate the static class: Ex:

    static class myStaticClass
    {
        public static void someFunction()
        { /* */ }
    }
    

    You can not make like this:

    myStaticClass msc = new myStaticClass();  // it will cause an error
    

    You can make only:

    myStaticClass.someFunction();
    

提交回复
热议问题