2.9. static Class Members

Not all members of a class make sense as instance members. Some members provide a service or contain information that is independent of an individual class object. The current value of an integer, for example, is an instance member. The maximum value an integer can hold is not. It holds true for all integer objects.

We would not want each integer object to hold a copy of the maximum value an integer can hold. However, it is information that users of the integer type would like to retrieve and to compare individual instances against.

That is, the maximum integer value makes sense as a member of the class representing the integer type. It does not make sense as an instance member of that class. This is why we declare certain ...

Get C# Primer: A Practical Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.