2.3. Declaring Data Members

A data member represents state information associated with an instance of a class, such as the name of a file or the capacity of an ArrayList. A class data member can be of any type. How do we discover the data members that we need to associate with a class?

One category of data members is the set that users provide when they create a class instance. For example, for our WordCount class, we require users to provide the name of a text file and optionally to indicate whether they wish a program trace or performance timings. It is likely that we'll need to store these values in associated class data members.

A second category of data members is the set of objects that are used across multiple member functions. If an object ...

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.