1.4. Making a Statement

The first thing we need to do is determine if the user specified any arguments. We do this by asking args the number of elements it contains.[3] For our program I decided that if the user doesn't supply the necessary command-line arguments, the program shuts down. (As an exercise, you may wish to reimplement the program to allow the user to interactively enter the desired options. The program is certainly friendlier that way.)

[3] In C#, we cannot write if (!args.Length) to test whether the array is empty because 0 is not interpreted as meaning false.

In my implementation, if args is empty, the program prints an explanation of the correct way to invoke WordCount, then exits using a return statement. (The return statement ...

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.