7.5. Static Members
Up until this point, all the methods, fields, and properties that we've discussed have been associated with an instance of a class. Every object has its own copy of the member and can manipulate it independently of what other objects are doing. But there might be times when you'll want to make a member common to all instances of a class. In other words, instead of having each object have its own copy of a field, there might be a field whose value will be shared by all objects of a given class. A common field, for example, can be useful to keep track of how many objects of a given type have been instantiated in an application. The C# language satisfies this need through static members that are associated with classes as a ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access