C# Get Started
How to setup C# environment.
C# IDE
The easiest way to get started with C# is to use an IDE.
An IDE (Integrated Development Environment) is used to edit and compile code.
In our tutorial, we will use Visual Studio Community, which is free to download from Microsoft.
Applications written in C# use the .NET Framework, so it makes sense to use Visual Studio, as the program, the framework, and the language, are all created by Microsoft.
C# Install
Once Visual Studio is installed, you can start creating a new project:
- Open Visual Studio
- Click on "Create a new project"
- Select "Console App (.NET Core)" from the list and click "Next"
- Enter a name for your project, and click "Create"
Visual Studio will automatically generate some code for your project:
using System;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
Examples
First Program
The classic 'Hello World' program.
using System;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}Running Code
Simple output to verify setup.
using System;
namespace Test
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("It works!");
}
}
}Multiple Lines
Printing multiple lines.
using System;
namespace MultiLine
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Line 1");
Console.WriteLine("Line 2");
}
}
}