O'Reilly logo

C# Primer: A Practical Approach by Stanley B. Lippman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

2.7. The Class Constructor

Our WordCount program requires that the user provide a file name. Optionally, the user can turn on several options, such as generating trace output and timing diagnostics. The Main() entry point processes the command-line options. That done, it must create a WordCount object and pass the file name and possible options to that object before asking the object to process the file.

One solution, of course, is to create a WordCount object with the default values and then reset the values the user passed in through the command-line options. The problem with this strategy is that it requires two steps, and the crucial second one is something that the user might overlook.

The class constructor is a mechanism by which the user ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required