Interacting with Programs

One of the things done with many programs is user interaction at runtime. You can do this on the command line. This knowledge may be useful if there's a need to create a command-line utility. Listing 2.2 shows an example of interacting with a program via the command line.

Listing 2.2. An Interactive Program
 1: /* 2: Filename: HelloName.cs 3: Author: Joe Mayo 4: */ 5: 6: using System; // use the System namespace 7: 8: class HelloName 9:{ 10: static void Main() 11: { 12: string name; // holds user's name 13: 14: // Ask for input 15: Console.Write("What is your name?: "); 16: 17: // Get user's input 18: name = Console.ReadLine(); 19: 20: // Print greeting to console 21: Console.WriteLine("Hello, {0}! ", name); 22: } 23: ...

Get C# Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.