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

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 ...

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