Skip to main content

C# (pronounced "see sharp") is a high-level, statically typed, multi-paradigm programming language developed by Microsoft. C# code usually targets Microsoft's .NET ecosystem, which include .NET, .NET Framework, .NET MAUI, and Xamarin among others. Use this tag for questions about code written in C# or about C#'s formal specification.

is a multi-paradigm programming language including object-oriented programming, functional programming, and imperative programming created by Microsoft in conjunction with .NET. C# can be used with any .NET implementation such as .NET, .NET Framework, Mono, ML.Net and Xamarin.

Versions

Version ECMA¹ ISO/IEC¹ Microsoft¹ Date .Net Version Visual Studio
C# 1.0 December 2002 April 2003 January 2002 January 2002 .NET Framework 1.0 Visual Studio .NET 2002
C# 1.1 October 2003 April 2003 .NET Framework 1.1 Visual Studio .NET 2003
C# 1.2
C# 2.0 June 2006 September 2006 September 2005 .NET Framework 2.0 Visual Studio .NET 2005
.NET Framework 3.0 Visual Studio .NET 2008
C# 3.0 August 2007 November 2007 .NET Framework 2.0 (Except LINQ) Visual Studio 2008
.NET Framework 3.0 (Expect LINQ)
.NET Framework 3.5
C# 4.0 April 2010 April 2010 .NET Framework 4 Visual Studio 2010
C# 5.0 December 2017 December 2018 June 2013 August 2012 .NET Framework 4.5 Visual Studio 2012
Visual Studio 2013
Draft .NET Framework 4.6 Visual Studio 2015
C# 6.0 July 2015 .NET Core 1.0
.NET Core 1.1
C# 7.0 ² March 2017 .NET Framework 4.7 Visual Studio 2017 version 15.0
C# 7.1 ² August 2017 .NET Core 2.0 Visual Studio 2017 version 15.3
C# 7.2 ² November 2017 - Visual Studio 2017 version 15.5
² .NET Core 2.1 Visual Studio 2017 version 15.7
C# 7.3 May 2018 .NET Core 2.2
.NET Framework 4.8
C# 8 ² September 2019 .NET Core 3.0 Visual Studio 2019 version 16.3
C# 9.0 ² September 2020 .NET 5.0 Visual Studio 2019 version 16.8
C# 10 ² November 2021 .NET 6.0 Visual Studio 2022 version 17.0
C# 11 ² November 2022 .NET 7.0 Visual Studio 2022 version 17.4
C# 12 ² November 2023 .NET 8.0 Visual Studio 2022 version 17.6

¹: Language specification

²: Specification proposal

New features

Versions 1.0/1.2 and 2.0 of C# were submitted and approved as both ECMA (Web-Version) and ISO/IEC standards. Latest ECMA version matches Microsoft C# 5.0 specification. Language specifications are also available from Microsoft for C# 3.0 and C# 5.0 as well as C# 6.0 draft.

The language's type system was originally static, with only explicit variable declarations allowed. The introduction of var (C# 3.0) and dynamic (C# 4.0) allowed it to use type inference for implicit variable typing, and to consume dynamic type systems, respectively. Delegates, especially with lexical closure support for anonymous methods (C# 2.0) and lambda expressions (C# 3.0), allow the language to be used for functional programming.

C# 5.0 introduced the async and await keywords to simplify the use of asynchronous function calls.

C# 6.0 introduced the null propagation operator ?., exception filters, string interpolation, and many other features that help to write simple code.

C# 7.0 introduced multiple out arguments, pattern matching, tuples for a return value, is-expressions & switch statements with patterns, deconstruction, local functions, and some more.

C# 7.1 introduced generic Pattern Matching, inferred tuple element names, default literal expressions, async main, and some more.

C# 7.2 introduced private protected, non-trailing named arguments, digital separator after base specifier, ref conditional expression, reference semantics for value types, and some more.

C# 7.3 introduced features that enable safe code to be as performant as unsafe code, new compiler options, the usage of out variable declarations in field, property and constructor initializers, support == and != on tuple types and some more.

C# 8.0 introduced nullable reference types which generates compiler warnings about possible dereferencing of nulls unless the code expresses explicitly that a variable may be null (e.g., string? foo is a variable which may be null), async streams which empowers -especially- IoT and cloud integrations and default interface methods to prevent breaking changes to interfaces, along with some other improvements.

C# 9.0 introduced plenty of new concepts and features such as Records, Init only setters, Top-level statements, Pattern matching enhancements and more.

The compilation is usually done in the Microsoft Intermediate Language (MSIL), which is then JIT-compiled to native code (and cached) during execution in the Common Language Runtime (CLR). However, options like NGen (for the .NET Framework) and AOT (for Mono) mean that C# code can be directly compiled into the native image. Additionally, some frameworks (for example, the .NET Micro Framework) act as CIL interpreters, with no JIT.

Generics in C# are provided in part by the runtime, unlike C++ templates (templates are resolved at compile time), or Java's generics (which use type-erasure).

With the combination of .NET Core for Windows, macOS and Linux, .NET Framework for Windows (desktop/server/mobile), Mono that powers Xamarin applications on Android, Mac, iOS, tvOS and watchOS, Silverlight/Moonlight (browser/mobile), Compact Framework (mobile), and Micro Framework (embedded devices), it's available for a wide range of platforms.

C# 10 introduced file-scoped namespace declarations, global using directives, implicit usings, record structs, along with some other improvements.

C# 11 introduced raw string literals, required members, generic attributes, list patterns, file-local types, generic math support and more.

C# 12 Improved Support for Interpolated Strings, Primary Constructors for All Classes and Structs, Collection Expressions, Inline Arrays, Default Parameters for Lambda Expressions, Ref Readonly Parameters and more.


Hello World Example:

using System;

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

Hello World example using classes:

using System;

namespace HelloWorldUsingClasses
{
    class Greeting
    {
        public static void SayHello()
        {
            Console.WriteLine("Hello World!");
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Greeting.SayHello();
        }
    }
}

Hello World example since .NET 6:

// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");

Stack Overflow resources


FAQs


Release Notes


Resources


Books


Tutorials


Future of C# language

Contribute and propose new features here.


Demo Projects


C# Online IDE


C# Offline IDE

Related tags

Code Language (used for syntax highlighting): lang-cs