C# Get Started

Before you can write real C# programs, you need a place to write and run your code. In this lesson you will learn what tools you need to get started, how a basic program is organized, and how to run your very first program.

Setting up your tools

To write and run C# code on your own computer, you need the .NET SDK (Software Development Kit). The SDK includes the compiler that turns your C# code into a program the computer can run, plus everything else you need to build applications.

  • Download and install the free .NET SDK from the official Microsoft website.
  • Install a code editor such as Visual Studio Code or the full Visual Studio.
  • Open a terminal to run commands like dotnet run.
  • Or simply use an online C# editor to practice without installing anything.
Note: If you just want to practice the examples in this tutorial, an online C# compiler is the fastest way to start. You can install the SDK later when you build bigger projects.

Your first program

Once your tools are ready, create a file with a .cs extension, for example Program.cs, and type the code below. This is the classic starting point for learning any language: a program that greets the world.

Program.cs

using System;

class Program
{
    static void Main()
    {
        Console.WriteLine("Hello World!");
    }
}

When you run this program, it prints the text Hello World! and then finishes. Running it from a terminal is usually done with the dotnet run command inside your project folder.

Understanding the parts

PartWhat it does
using System;Gives you access to common features like Console
class ProgramGroups your code together in a named block
static void Main()The entry point where the program starts running
Console.WriteLinePrints a line of text to the screen

Printing more than one line

using System;

class Program
{
    static void Main()
    {
        Console.WriteLine("Setup complete.");
        Console.WriteLine("Ready to code in C#!");
    }
}
Note: C# is case sensitive. Console with a capital C works, but console with a lowercase c will cause an error.

Exercise: C# Get Started

What is the conventional entry point method of a C# console app?