Polyglot
Languages C#
Volume C#

C#

A general-purpose, statically typed, multi-paradigm programming language developed by Microsoft. Compiled to the Common Intermediate Language and executed by the .NET runtime; standardised through ECMA and ISO.

Paradigms
imperative · OOP · functional
Typing
static
Memory
gc
Version
13
First released
2000

C# is a general-purpose, statically typed, multi-paradigm programming language developed by Microsoft and standardised by ECMA and ISO. Programs are compiled to the Common Intermediate Language (CIL) and executed by the Common Language Runtime (CLR), the managed execution environment of the .NET platform. The language emphasises type safety, automatic memory management through a tracing garbage collector, and a substantial standard library; subsequent revisions have added generics, language-integrated query (LINQ), asynchronous programming with async/await, nullable reference types, records, and pattern matching, in a series of additive revisions that have nevertheless preserved a high degree of backward compatibility.

History

C# was designed by Anders Hejlsberg and a team at Microsoft beginning in 1999, initially under the project name Cool. C# 1.0 shipped in February 2002 alongside .NET Framework 1.0. ECMA standardised the language in December 2002 as ECMA-334; ISO ratified the same specification in 2003 as ISO/IEC 23270. Subsequent revisions have been substantial: C# 2.0 (2005) introduced generics and nullable value types; C# 3.0 (2007) introduced LINQ, lambda expressions, and extension methods; C# 5.0 (2012) introduced async/await; C# 6 (2015) added string interpolation and expression-bodied members; C# 7 through C# 9 introduced tuples, pattern matching, and records; C# 10 introduced file-scoped namespaces and global usings; C# 11 (2022) added required members and raw string literals; C# 12 added primary constructors. The current revision is C# 13, shipped with .NET 9 in 2024.

Hello world

using System;

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

Since .NET 6, top-level statements permit a program without an enclosing class:

Console.WriteLine("Hello, world!");

The conventional toolchain is the cross-platform dotnet CLI:

dotnet new console -o hello
cd hello
dotnet run

dotnet invokes the Roslyn compiler to produce CIL, the runtime then executes the result through just-in-time compilation. The reference runtime is .NET, the open-source cross-platform successor to the Windows-only .NET Framework; Mono provides an alternative implementation used on platforms that pre-date .NET 6.