Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 182 ยท Getting Started

Getting Started with C#

Start learning C# 14 on .NET 10. Learn what C# and .NET are, where they are used, and write and run your first program right in your browser.

C# (pronounced "C sharp") is a modern, general-purpose programming language created at Microsoft by Anders Hejlsberg's team and first released in 2002. It is statically typed, object-oriented, and increasingly functional in style. You write code, a compiler checks it before it ever runs, and the checked program then runs on a fast runtime. That combination catches a huge number of mistakes early, which is one reason C# is trusted for large, long-lived software.

C# does not live alone. It runs on .NET, a free, open-source platform that provides the runtime, the standard library and the tools. When people say "I write .NET," they almost always mean "I write C# on .NET." This tutorial teaches C# 14 on .NET 10, a long-term-support (LTS) release from November 2025, and every example in it runs right here in your browser.

What people build with C#

C# is one of the most versatile languages in everyday use:

  • Web backends and APIs. ASP.NET Core is among the fastest mainstream web frameworks. You will meet it in the ASP.NET Core chapter.
  • Games. Unity, one of the most popular game engines, uses C# for gameplay scripting. Godot supports it too.
  • Desktop and mobile apps. WPF, WinForms, .NET MAUI and Avalonia build apps for Windows, macOS, Linux, Android and iOS.
  • Cloud services and microservices. Azure Functions, background workers, message processors and containers.
  • Command-line tools and automation. Small programs that start quickly and ship as a single file.
  • Data and AI plumbing. Services that call machine-learning models, process streams and talk to databases.

You do not need to pick one of these now. The core language is the same everywhere, and this tutorial teaches it first.

Your first program

Here is a complete C# program. It is one line long.

C# Hello, C#

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

Press Run. The editor sends the code to our server, where it is compiled and executed, and the result appears underneath. Try changing the text and running again.

That single line is a complete program because of top-level statements, a feature added in C# 9. The compiler wraps your statements in a hidden Main method for you. Program Structure explains exactly what it generates. Older C# code, and a lot of code you will read, spells everything out:

C#
using System;

namespace HelloApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello, C#!");
        }
    }
}

Both do the same thing. The short form is the modern default, and it is what you will see in this tutorial.

Let us take the one-liner apart:

  • Console is a class from the standard library that represents the text window of your program.
  • WriteLine is a method of that class. It writes text and then moves to the next line.
  • "Hello, C#!" is a string literal, the text to print. It is the argument you hand to the method.
  • The semicolon ; ends the statement. C# statements always end with one.
  • There is no using System; at the top because modern projects turn on implicit usings, which automatically import the namespaces you use most. C# Syntax covers this.

More than one statement

Programs are made of statements that run from top to bottom, one after another.

C# A few statements in a row

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

The first two lines create variables: a named place to keep a value. string holds text and int holds whole numbers. You will learn them properly in Variables and var. The line with $"..." is an interpolated string: anything inside {} is replaced by its value. Notice that 2 + 3 * 4 prints 14, not 20, because multiplication binds tighter than addition, just as in maths.

Compile errors are your friend

C# is compiled, so your code is checked as a whole before any of it runs. If something is wrong, you get an error with an exact position and a code, and nothing runs. Experience this now: the program below has a deliberate mistake.

C# A first compile error (fails on purpose)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

The compiler reports main.cs(1,13): error CS0029: Cannot implicitly convert type 'string' to 'int'. Read it from left to right: file main.cs, line 1, column 13, error code CS0029, and then a plain-English message. You tried to put text into a variable that holds integers, so the compiler refused. The code is also searchable: typing CS0029 into a search engine always finds an explanation. You will read many such messages; they get friendly quickly. In dynamic languages this same mistake would hide until the line ran, possibly for a user in production.

When a program has several errors, fix the first one and run again. Later errors are often a knock-on effect of the first.

Doing something useful

Let us write a small program with a decision and a loop, a taste of what is coming in the Operators and Control Flow chapter.

C# A tiny program with a loop

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

You do not have to understand every symbol yet. In words: store five numbers in an array (the square-bracket syntax is a C# 12 collection expression), visit each one with foreach, add it to a running total, decide "pass" or "fail" with the ?: operator, and finally compute the average. {score,3} right-aligns the number in three characters and {average:F1} shows one decimal place; Console Output and Formatting covers both.

C# 14 on .NET 10, and the release rhythm

C# and .NET follow a predictable schedule: a new version every November, together with a new .NET release.

  • Even-numbered .NET releases (8, 10, 12, ...) are LTS: long-term support, three years of fixes. .NET 10 is one of those.
  • Odd-numbered releases are STS: standard-term support, which is shorter.
  • Each .NET release comes with a new C# version. .NET 8 had C# 12, .NET 9 had C# 13, and .NET 10 has C# 14.

C# is also backward compatible. Code written for C# 7 still compiles today. New versions add features rather than taking old ones away, so a tutorial on C# 14 is still valid for years. When this tutorial teaches something newer, such as primary constructors (C# 12) or the field keyword (C# 14), it tells you which version introduced it so you know what to expect in older codebases.

Our editor uses a compiler with the latest language version, nullable reference types turned on, and implicit usings. That matches what a new project created today gives you, so what you learn here transfers directly.

How to learn from this tutorial

  • Run every example. Then change it. Break it on purpose and read the error message.
  • Predict first. Before you press Run, say out loud what you expect to see. The gap between expectation and result is where learning happens.
  • Do the quizzes. They are short and they target the typical misunderstandings.
  • Follow the order. Each lesson builds on the previous ones, and links point back to anything you might have forgotten.

Many examples have a Program input box. When a program reads from the keyboard with Console.ReadLine(), whatever you type in that box is what it receives; there is a full lesson on it in Reading Input.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is the relationship between C# and .NET?

    C# is the programming language. .NET is the platform that provides the runtime, the standard library and the tools used to build and run C# programs.
  2. 2. Why does a program with a type mistake such as int count = "three"; not run at all?

    C# is a compiled, statically typed language. Type errors are found at compile time, with a file, line, column and error code, so no part of the program runs.
  3. 3. What does a top-level-statements program such as Console.WriteLine("Hi"); rely on?

    Since C# 9 the compiler wraps top-level statements in a generated entry point, so a single line can be a whole program.
  4. 4. Which statement about C# versions is true?

    The release rhythm is annual, in November. .NET 10 (with C# 14) is an LTS release, and C# stays backward compatible.

Summary

  • C# is a modern, statically typed language; .NET is the free, open-source platform that compiles and runs it.
  • C# is used for web backends, games (Unity), desktop and mobile apps, cloud services and command-line tools.
  • This tutorial uses C# 14 on .NET 10 (LTS), and all examples run in your browser.
  • Top-level statements make a single line a complete program: Console.WriteLine("Hello, C#!");.
  • Statements end with ;, and they run from top to bottom.
  • The compiler reports mistakes before running, with a file, a line, a column and a code such as CS0029.
  • A new C# and .NET version is released every November, and new versions stay backward compatible.

Next: How C# and .NET Work shows what happens between your source code and the running program.