What is the difference between class and instance methods?

后端 未结 18 2167
说谎
说谎 2020-11-21 11:55

What\'s the difference between a class method and an instance method?

Are instance methods the accessors (getters and setters) while class methods are pretty much ev

18条回答
  •  既然无缘
    2020-11-21 12:39

    An instance method applies to an instance of the class (i.e. an object) whereas a class method applies to the class itself.

    In C# a class method is marked static. Methods and properties not marked static are instance methods.

    class Foo {
      public static void ClassMethod() { ... }
      public void InstanceMethod() { ... }
    }
    

提交回复
热议问题