Hello World -- Your First C# Program



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.
  1. If Program.cs is not open in the Code Editor, right-click Program.cs in Solution Explorer and then click View Code.
  2. Replace the contents of Program.cs with the following code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HelloWorld
{
    class Program
    {
//The Main method is where you create objects and execute other methods.
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            // Keep the console window open in debug mode.
            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
        }
    }
}

9) Press F5 to run the project. A Command Prompt window appears that contains the line Hello World!



Comments

Popular posts from this blog

Basic components of .NET platform

Did you know… You can go directly to the installed code samples from within Visual Studio?