๐ŸŽ“ A1Learner
๐Ÿ”

C# Get Started

Getting started with C# is the path from a written file to a running program. The dotnet tool creates the project and runs the code.

The full shape

A project is a folder that holds one program. This program uses the full shape of this course.

using System;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Let's get started.");
    }
}

Two statements in order

Two statements sit inside Main. Each statement ends with a semicolon.

using System;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("First step");
        Console.WriteLine("Second step");
    }
}

Example

using System;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Program started.");
        Console.WriteLine("Program finished.");
    }
}

Key points

  • The dotnet new console command creates a new project.
  • The dotnet run command builds a project and runs it.
  • using System brings in the built-in System tools.
  • class Program is the container for the program code.
  • Main is the method where running starts.
  • A real new project starts with a shorter top-level form.
  • This course uses the fuller classic form so later lessons can add classes.

In this example, the first line prints Program started. The second line prints Program finished. The two lines appear in the order of the code.

Note

A pasted classic program compiles unchanged inside a new project.

Try it Yourself

Edit the code, then press Run.

Running is simulated ยท Programiz C# Compiler

Exercise

Which command builds a project and runs it?