3 min read
Static Members
Prerequisites: Access modifiers
class Counter {
public static int TotalCreated = 0;
public int Id;
public Counter() {
TotalCreated++;
Id = TotalCreated;
}
}
var a = new Counter();
var b = new Counter();
Console.WriteLine(Counter.TotalCreated); // 2
Exactly as in Java, a static member belongs to the class itself,
shared across every instance.