2.4. Properties

Often the internal representation of a class is modified after its initial release to users. For example, in this first version of WordCount, m_trace is declared as a bool data member; that is, it is able to be set either to true or to false. For large text files, however, users have found the generated trace text overwhelming—at least when generated to the console. They have requested that we allow them to specify whether to direct the trace to the console or to a file. Supporting this flexibility requires a change to the type representation of m_trace. It must now be able to represent three states: traceOff, toConsole, and toFile.

If m_trace is declared as public, users are free to access it directly within their code. The result ...

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.