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.
Welcome. Go to File → New** → Project**.
Click Templates → Visual C# → Console Application
(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.)
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();
}
}
}
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.