Download and install Visual Studio. Visual Studio can be downloaded from VisualStudio.com. The Community edition is suggested, first because it is free, and second because it involves all the general features and can be extended further.
Open Visual Studio.
Click Templates → Visual C# → Console Application
After selecting Console Application, Enter a name for your project, and a location to save and press OK. Don't worry about the Solution name.
Project created. The newly created project will look similar to:
(Always use descriptive names for projects so that they can easily be distinguished from other projects. It is recommended not to use spaces in project or class name.)
Write code. You can now update your Program.cs
to present "Hello world!" to the user.
using System;
namespace ConsoleApplication1
{
public class Program
{
public static void Main(string[] args)
{
}
}
}
Add the following two lines to the public static void Main(string[] args)
object in Program.cs
: (make sure it's inside the braces)
Console.WriteLine("Hello world!");
Console.Read();
Why Console.Read()
? The first line prints out the text "Hello world!" to the console, and the second line waits for a single character to be entered; in effect, this causes the program to pause execution so that you're able to see the output while debugging. Without Console.Read();
, when you start debugging the application it will just print "Hello world!" to the console and then immediately close. Your code window should now look like the following:
using System;
namespace ConsoleApplication1
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello world!");
Console.Read();
}
}
}
Debug your program. Press the Start Button on the toolbar near the top of the window or press F5 on your keyboard to run your application. If the button is not present, you can run the program from the top menu: Debug → Start Debugging. The program will compile and then open a console window. It should look similar to the following screenshot:
Console.Read()
we added was for this same purpose. Another way to close the program is by going to the menu where the Start button was, and clicking on the Stop button.