C# (pronounced "C sharp") is a general-purpose programming language designed at Microsoft by a team led by Anders Hejlsberg, first released in 2002. It is statically typed (every variable has a type the compiler checks before the program runs), object-oriented (code is organized into classes), and managed (a garbage collector frees memory for you). Modern C# also borrows heavily from functional programming: lambdas, LINQ queries, pattern matching and immutable records.
Here is a complete C# program. Press Run:
Output:
Hello, Ada! It is 2026.
What C# is used for
C# is a general-purpose language, so it is found in most kinds of software, but a few areas account for most of it:
- Games. Unity, one of the most widely used game engines, is scripted in C#. Godot supports it as well.
- Web backends. ASP.NET Core is the .NET web framework for APIs, websites and real-time apps. It is one of the fastest mainstream web frameworks in public benchmarks.
- Desktop apps. WPF and Windows Forms on Windows, .NET MAUI and Avalonia across platforms.
- Cloud and services. Azure Functions, background workers, microservices in containers.
- Tools and automation. Command-line tools, build scripts, data processing.
It is especially common in enterprise companies that run on Microsoft technology and in game studios. Mobile apps are possible with .NET MAUI (the successor to Xamarin), but that is a smaller niche than Kotlin or Swift.
C# and .NET are not the same thing
C# is the language. .NET is the platform that runs it, and it has three parts:
- The runtime (CLR). The C# compiler does not produce machine code. It produces Intermediate Language (IL), stored in
.dllor.exefiles. When the program runs, the Common Language Runtime compiles that IL to native code just in time (JIT), manages memory with a garbage collector, and enforces type safety. - The base class library. Collections, file access, networking, text, dates, threading: everything under
System.*. - The SDK. The
dotnetcommand that creates, builds, tests and runs projects.
Other languages compile to the same IL (F#, Visual Basic), which is why a C# program can use a library written in F#.
There are two generations of the platform. .NET Framework (1.0 in 2002 to 4.8.1) is Windows only and still runs many older applications. .NET (called .NET Core until version 5) is the open source, cross-platform successor that runs on Windows, Linux and macOS. New work targets .NET; even-numbered releases such as .NET 8 and .NET 10 get three years of long-term support.
How a C# program is structured
A C# program is made of types (classes, structs, interfaces, enums, records) that contain members (fields, properties, methods). Execution starts in a static method named Main. Namespaces group related types, and using directives let you refer to them by short names.
Output:
Maya: 21.00
Leo: 13.00
A few things are already visible: Order is a class with two properties (Customer, Total), a constructor, and a method. decimal is the type for money, and the m suffix marks a decimal literal. var lets the compiler infer a local variable's type, and List<Order> is a generic collection that only accepts Order objects. The {order.Total:F2} inside $"..." formats a number with two decimals.
In a real project each class usually lives in its own file, and the files are compiled together into one assembly. See classes and objects for the details.
Static typing, in practice
The compiler knows the type of every expression, so a large class of mistakes never reaches a running program. Assigning a string to an int, calling a method that does not exist, or passing arguments in the wrong order fails at compile time with an error pointing at the line.
Output:
29.97
45
Types also drive the editor: autocomplete, rename and "find all references" are exact in C# because the tooling reads the same type information the compiler does.
C# versions and what they added
Since C# 9 in 2020, a new version ships every November together with a new .NET release; before that, versions came every two to three years. Each version is designed to keep existing code compiling, and the rare exceptions (such as field becoming a keyword inside property accessors in C# 14) are documented as breaking changes, so a program written for C# 2 almost always compiles unchanged today.
| Version | Year | Notable additions |
|---|---|---|
| C# 2 | 2005 | Generics, nullable value types (int?), iterators (yield) |
| C# 3 | 2007 | LINQ, lambda expressions, var, object initializers, extension methods |
| C# 4 | 2010 | dynamic, optional and named parameters |
| C# 5 | 2012 | async and await |
| C# 6 | 2015 | String interpolation $"...", nameof, null-conditional ?. |
| C# 7 | 2017 | Tuples, out var, pattern matching with is, digit separators |
| C# 8 | 2019 | Nullable reference types, switch expressions, ranges s[1..4], ??=, async streams |
| C# 9 | 2020 | Records, init accessors, top-level statements, target-typed new() |
| C# 10 | 2021 | Global usings, file-scoped namespaces, record structs |
| C# 11 | 2022 | Raw string literals """, required members, list patterns |
| C# 12 | 2023 | Primary constructors for classes, collection expressions [1, 2, 3] |
| C# 13 | 2024 | params collections, the System.Threading.Lock type |
| C# 14 | 2025 | Extension members, the field keyword in properties |
Newer versions mostly remove ceremony. This C# 9 and later program uses top-level statements (no class Program, no Main), a record and a switch expression:
// C# 9 and later, in a .NET 6+ project (implicit usings import System)
var order = new Order("Maya", 21.00m);
Console.WriteLine(Shipping(order));
static string Shipping(Order o) => o.Total switch
{
>= 50m => "free shipping",
>= 20m => "standard shipping",
_ => "shipping fee applies"
};
record Order(string Customer, decimal Total);
The same logic in the older explicit style, which compiles on C# 6 and every later version:
Output:
standard shipping
Both forms are valid C#. You will meet the older, explicit style in existing code, tutorials and Unity projects, and the shorter style in new .NET projects.
LINQ: querying data in the language
LINQ (Language Integrated Query, C# 3) is one of the features people cite when they explain why they like C#. It lets you filter, sort, group and transform any collection with a chain of methods:
Output:
95, 91, 88, 72
Average: 78.0
Best: 95
The same syntax works on lists in memory, on database tables through Entity Framework, and on XML. More in LINQ.
Is C# a good first language?
C# asks for more up front than Python: you declare types, end statements with semicolons, and put code inside classes. In exchange, the compiler catches mistakes early, the tooling (Visual Studio, VS Code, Rider) is excellent, and the concepts transfer directly to Java, TypeScript, Kotlin and C++. If you want to build Unity games or work in a .NET shop, it is the obvious choice. If your goal is data analysis or machine learning, Python has the larger ecosystem.
To start, install the .NET SDK and run dotnet new console, or begin with Hello World and run the examples on these pages directly.
Frequently Asked Questions
What is C#?
C# (pronounced "C sharp") is a statically typed, object-oriented, general-purpose programming language created at Microsoft and first released in 2002. Its source code compiles to an intermediate language that the .NET runtime turns into machine code, with garbage-collected memory. It is used for web backends, Unity games, desktop apps, cloud services and tools.
Is C# the same as .NET?
No. C# is the language; .NET is the platform it runs on: the runtime (CLR), the base class library (System.Collections.Generic, System.IO, and so on) and the SDK tools. F# and Visual Basic also run on .NET, and a C# version usually ships alongside a .NET version (C# 12 with .NET 8, for example).
What is C# used for?
Web APIs and sites with ASP.NET Core, games with Unity (its scripting language is C#), Windows desktop apps with WPF and WinForms, cross-platform apps with .NET MAUI, cloud services and Azure Functions, and command-line tools. It is common in enterprise software and game studios.
Is C# hard to learn?
It is a moderate first language. The syntax is C-style and stricter than Python, since every variable has a type the compiler checks, but memory is managed for you and error messages are clear. Most beginners can write useful console programs within a few weeks of practice.
Is C# still worth learning?
Yes. C# is consistently among the most used languages in developer surveys, .NET is open source and cross-platform, and the language gets a new version every November. It is the practical choice if you want to make games in Unity or work in companies built on Microsoft technology.