C# Get Started
C# IDE
The easiest way to get started with C# is to use an IDE.
An IDE (Integrated Development Environment) is a program where you write, run and fix your code.
In this tutorial, we use Visual Studio Community. It is free, and it is made by Microsoft, the company that also makes C# and .NET. You can download it from https://visualstudio.microsoft.com/vs/community/.
C# Install
Follow these steps to install Visual Studio and create your first C# program:
- Download and run the Visual Studio Installer.
- Choose the .NET desktop development workload, and click Install.
- When the installation is complete, click Launch to start Visual Studio.
- On the start window, choose Create a new project.
- Choose Console App (the one with the C# tag) from the list, and click Next.
- Enter a name for your project, for example HelloWorld, and click Next.
- Choose the newest .NET version in the Framework list, check the box Do not use top-level statements, and click Create.
Visual Studio creates a file called Program.cs. The code should look something like this:
Program.cs
using System;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
Visual Studio may write internal class Program and leave out the using System; line. That is fine: the program works the same way.
Don't worry if you don't understand the code above. We will explain it in the next chapters. For now, focus on how to run the code.
Run the program by pressing F5 on your keyboard (or click the green Start button at the top). Visual Studio compiles and runs your code, and opens a window that shows the result:
Hello World!
The window also shows a line that ends with "exited with code 0". This means that the program finished without errors. Press any key to close the window.
Congratulations! You have now written and run your first C# program.
Learning C# At W3Schools
When learning C# at W3Schools.com, you can use our "Try it Yourself" tool, which shows both the code and the result. This will make it easier for you to understand every part as we move forward:
Program.cs
using System;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
Result:
Hello World!