C#
C# was designed by Anders Hejlsberg at Microsoft and released in 2002 with the .NET Framework. It started as a Java-like object-oriented language and grew steadily, borrowing functional ideas (LINQ, pattern matching, records) and asynchronous programming while staying statically typed.
Paradigm: Systems Multi-Paradigm Languages
What Makes C# Special
- Object-oriented core. Classes, interfaces, properties, events and generics are the base. The language is designed around components that plug together.
- LINQ. Language Integrated Query lets you filter, sort and project any collection with SQL-like or method syntax, using lambdas. It is functional style over objects.
- Pattern matching and records.
switchexpressions, type patterns and positional patterns work well withrecordtypes, which are immutable data classes with value equality. - async and await. Asynchronous code reads like sequential code. The compiler turns an
asyncmethod into a state machine. - Managed, with escape hatches. A garbage collector manages memory, but value types (
struct),Span<T>andunsafecode give control when performance needs it, and Native AOT compiles to a native binary. - Nullable reference types. The compiler tracks which references may be null and warns before a null dereference.
Example: LINQ, pattern matching and async in a few lines
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
var people = new List<Person> { new("Ada", 36), new("Linus", 28), new("Grace", 45) };
// functional: LINQ with lambdas
var names = people.Where(p => p.Age > 30).OrderBy(p => p.Name).Select(p => p.Name);
Console.WriteLine(string.Join(", ", names)); // Ada, Grace
// pattern matching with a switch expression
foreach (object o in new object[] { 42, "hi", people[0] })
{
Console.WriteLine(o switch
{
int n when n > 40 => $"big int {n}",
string s => $"string of {s.Length}",
Person(var name, _) => $"person {name}",
_ => "other"
});
}
// asynchronous code that reads sequentially
static async Task<int> SlowAsync()
{
await Task.Delay(50);
return 7;
}
Console.WriteLine(await SlowAsync()); // 7
record Person(string Name, int Age);
How It Works
record Person(string Name, int Age)declares an immutable class with properties, equality, printing and aDeconstructmethod in one line.- The LINQ query reads left to right: keep people over 30, sort by name, take the names. Nothing runs until
string.Joinenumerates the result. - The
switchexpression tests type and value.Person(var name, _)is a positional pattern that uses the record'sDeconstruct. awaitfrees the thread while the delay runs. The method resumes afterwards and returns 7.
History and Where It Is Used
C# is used for web services (ASP.NET Core), desktop applications, games (the Unity engine), mobile apps (.NET MAUI), cloud services and tools. .NET is open source and cross-platform, and C# gets a new version every year. Its design borrows from Java, C++ and functional languages, and F# shares its runtime. See also the full C# roadmap on this site.
Learn More
- C# documentation
- A tour of C#
- .NET
- Back to Systems Multi-Paradigm Languages or the PGP roadmap.