O'Reilly logo

C# 5.0 Unleashed by Bart De Smet

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

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

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