Hello World - Your First Program (C# Programming Guide)

The following procedure creates a C# version of the traditional "Hello World!" program. The program displays the string Hello World!

To create and run a console application

  1. Start Visual Studio.
  2. On the File menu, point to New, and then click Project.
  3. In the Templates Categories pane, expand Visual C#, and then click Windows.
  4. In the Templates pane, click Console Application.
  5. Type a name for your project in the Name field.
  6. Click OK.
    The new project appears in Solution Explorer.
  7. If Program.cs is not open in the Code Editor, right-click Program.cs in Solution Explorer and then click View Code.
  8. Replace the contents of Program.cs with the following code.
    // A Hello World! program in C#.
    using System;
    namespace HelloWorld
        class Hello 
            static void Main() 
                Console.WriteLine("Hello World!");
                // Keep the console window open in debug mode.
                Console.WriteLine("Press any key to exit.");
  9. Press F5 to run the project. A Command Prompt window appears that contains the line Hello World!
// A Hello World! program in C#.

You can also comment out a block of text by enclosing it between the /* and */ characters. This is shown in the following example.
/* A "Hello World!" program in C#.
This program displays the string "Hello World!" on the screen. */

Popular posts from this blog



HSC Exam Time Table 2013 Arts, Commerce, Science