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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access