A static
function, unlike a regular (instance) function, is not associated with an instance of the class.
A static
class is a class which can only contain static
members, and therefore cannot be instantiated.
For example:
class SomeClass {
public int InstanceMethod() { return 1; }
public static int StaticMethod() { return 42; }
}
In order to call InstanceMethod
, you need an instance of the class:
SomeClass instance = new SomeClass();
instance.InstanceMethod(); //Fine
instance.StaticMethod(); //Won't compile
SomeClass.InstanceMethod(); //Won't compile
SomeClass.StaticMethod(); //Fine
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…