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 the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.