1. Open Visual Studio
  2. In the toolbar, go to FileNew Project
  3. Select the Console Application project type
  4. Open the file Program.cs in the Solution Explorer
  5. Add the following code to Main():
public class Program
{
    public static void Main()
    {
        // Prints a message to the console.
        System.Console.WriteLine("Hello, World!");
				/* Wait for the user to press a key. This is a common
               way to prevent the console window from terminating
               and disappearing before the programmer can see the contents
               of the window, when the application is run via Start from within VS. */
        System.Console.ReadKey();
    }
}
  1. In the toolbar, click Debug -> Start Debugging or hit F5 or ctrl + F5 (running without debugger) to run the program.

Live Demo on ideone

Explanation

Using the command line

To compile via command line use either MSBuild or csc.exe (the C# compiler), both part of the Microsoft Build Tools package.

To compile this example, run the following command in the same directory where HelloWorld.cs is located:

%WINDIR%\\Microsoft.NET\\Framework64\\v4.0.30319\\csc.exe HelloWorld.cs

It can also be possible that you have two main methods inside one application. In this case, you have to tell the compiler which main method to execute by typing the following command in the console.(suppose Class ClassA also has a main method in the same HelloWorld.cs file in HelloWorld namespace)

%WINDIR%\\Microsoft.NET\\Framework64\\v4.0.30319\\csc.exe HelloWorld.cs /main:HelloWorld.ClassA

where HelloWorld is namespace