Writing the Code

Clichés need to be honored from time to time, so what’s better than starting with a good old Hello World program? Okay, let’s make it a little more complicated by making a generalized Hello program, asking for the user’s name to show a personalized greeting message.

Open up Notepad, enter the following code, and save it to a file called Hello.cs:

using System;class Program{    static void Main()    {        Console.Write("Enter your name: ");        string name = Console.ReadLine();        Console.WriteLine("Hello " + name);    }}

Make sure to respect the case of letters: C# is a case-sensitive language. In particular, if you come from a Java or C/C++ background, be sure to spell Main with a capital ...

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

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