C# ( ) is a general-purpose high-level programming language supporting multiple paradigms. C# encompasses static typing, strong typing, lexically scoped, imperative, declarative, functional, generic, object-oriented (class-based), and component-oriented programming disciplines.

The principal designers of the C# programming language were Anders Hejlsberg, Scott Wiltamuth, and Peter Golde from Microsoft. It was first widely distributed in July 2000 and was later approved as an international standard by Ecma (ECMA-334) in 2002 and ISO/IEC (ISO/IEC 23270 and 20619) in 2003. Microsoft introduced C# along with .NET Framework and Microsoft Visual Studio, both of which are, technically speaking, closed-source. At the time, Microsoft had no open-source products. Four years later, in 2004, a free and open-source project called Mono began, providing a cross-platform compiler and runtime environment for the C# programming language. A decade later, Microsoft released Visual Studio Code (code editor), Roslyn (compiler), and the unified .NET platform (software framework), all of which support C# and are free, open-source, and cross-platform. Mono also joined Microsoft, but was not merged into .NET.

the most recent stable version of the language is C# 14.

Design goals The Ecma standard lists these design goals for C#:

The language is intended to be a simple, modern, general-purpose, object-oriented programming language. The language, and implementations thereof, should provide support for software engineering principles such as strong type checking, array bounds checking, detection of attempts to use uninitialized variables, and automatic garbage collection. Software robustness, durability, and programmer productivity are important. The language is intended for use in developing software components suitable for deployment in distributed environments. Portability is very important for source code and programmers, especially those already familiar with C and C++. Support for internationalization is very important. C# is intended to be suitable for writing applications for both hosted and embedded systems, ranging from the very large that use sophisticated operating systems, down to the very small having dedicated functions. Although C# applications are intended to be economical with regard to memory and processing power requirements, the language was not intended to compete directly on performance and size with C or assembly language.

History

During the development of the .NET Framework, the class libraries were originally written using a managed code compiler system named Simple Managed C (SMC). In January 1999, Anders Hejlsberg formed a team to build a new language at the time called COOL, which stood for "C-like Object Oriented Language".

Microsoft had considered keeping the name "COOL(C-like Object Oriented Language)" as the final name of the language, but chose not to do so for trademark reasons. By the time the .NET project was publicly announced at the July 2000 Professional Developers Conference, the language had been renamed C#, and the class libraries and ASP.NET runtime were ported to C#.

Hejlsberg was C#'s principal designer and lead architect at Microsoft, and had been previously involved with the design of Turbo Pascal, Embarcadero Delphi (formerly CodeGear Delphi, Inprise Delphi and Borland Delphi), and Visual J++. In interviews and technical papers, he has stated that flaws in most major programming languages (e.g. C++, Java, Delphi, and Smalltalk) drove the fundamentals of the Common Language Runtime (CLR), which, in turn, drove the design of the C# language.

James Gosling, who created the Java programming language in 1994, and Bill Joy, a co-founder of Sun Microsystems, the originator of Java, called C# an "imitation" of Java; Gosling further said: "[C# is] sort of Java with reliability, productivity and security deleted."

In July 2000, Hejlsberg said that C# is "not a Java clone" and is "much closer to C++" in its design.

Since the release of C# 2.0 in November 2005, the C# and Java languages have evolved on increasingly divergent trajectories, becoming two quite different languages. One of the first major departures came with the addition of generics to both languages, with vastly different implementations. C# uses reification to provide "first-class" generic objects that can be used like any other class, with code generation performed at class-load time.

C# has also added several major features to accommodate functional-style programming, culminating in the LINQ extensions released with C# 3.0 and its supporting framework of lambda expressions, extension methods, and anonymous types. These features enable C# programmers to use functional programming techniques, such as closures, when it is advantageous to their application. The LINQ extensions and the functional imports help developers reduce the amount of boilerplate code included in common tasks such as querying a database, parsing an XML file, or searching through a data structure, shifting the emphasis onto the actual program logic to help improve readability and maintainability.

C# used to have a mascot called Andy (named after Anders Hejlsberg). It was retired on January 29, 2004.

C# was originally submitted to the ISO/IEC JTC 1 subcommittee SC 22 for review, under ISO/IEC 23270:2003, was withdrawn and was then approved under ISO/IEC 23270:2006. The 23270:2006 is withdrawn under 23270:2018 and approved with this version.

Name Microsoft first used the name C# in 1988 for a variant of the C language designed for incremental compilation. That project was not completed, and the name was later reused.

The name "C sharp" was inspired by the musical notation whereby a sharp symbol indicates that the written note should be made a semitone higher in pitch. This is similar to the language name of C++, where "++" indicates that a variable should be incremented by 1 after being evaluated. The sharp symbol also resembles a ligature of four "+" symbols (in a two-by-two grid), further implying that the language is an increment of C++.

Due to technical limits of display (standard fonts, browsers, etc.), and most keyboard layouts lacking a sharp symbol (), the number sign () was chosen to approximate the sharp symbol in the written name of the programming language. This convention is reflected in the ECMA-334 C# Language Specification.

The "sharp" suffix has been used by a number of other Microsoft .NET compatible/compliant languages that are variants of existing languages, including J# (a .NET language also designed by Microsoft that is derived from Java 1.1), A# (from Ada), and the functional programming language F#. The original implementation of Eiffel for .NET was called Eiffel#, a name retired since the full Eiffel language is now supported. The suffix has also been used for libraries, such as Gtk# (a .NET wrapper for GTK and other GNOME libraries) and Cocoa# (a wrapper for Cocoa).

Versions Development of the text for standards (beginning with C# 6) is done on GitHub. C# 7 was submitted to Ecma and approved in December 2023. As of January 2024, the standard for C# 8 is currently under development, referencing the approved language proposals.

C#version Language specification Date .NET Visual Studio Ecma ISO/IEC Microsoft 1.0 ECMA-334:2003, December 2002 ISO/IEC 23270:2003, April 2003 January 2002 January 2002 .NET Framework 1.0 Visual Studio .NET 2002 1.11.2 October 2003 April 2003 Visual Studio .NET 2003 2.0 ECMA-334:2006, June 2006 ISO/IEC 23270:2006, September 2006 September 2005 November 2005 Visual Studio 2005Visual Studio 2008 3.0 colspan="2" rowspan="2" August 2007 November 2007 Visual Studio 2008 4.0 April 2010 April 2010 Visual Studio 2010 5.0 ECMA-334:2017, December 2017 ISO/IEC 23270:2018, December 2018 June 2013 August 2012 Visual Studio 2012Visual Studio 2013 6.0 ECMA-334:2022, June 2022 Draft July 2015 Visual Studio 2015 7.0 ECMA-334:2023, December 2023 ISO/IEC 20619:2023, September 2023 Specification proposal March 2017 Visual Studio 2017 version 15.0 7.1 Specification proposal August 2017 Visual Studio 2017 version 15.3 7.2 Specification proposal November 2017 Visual Studio 2017 version 15.5 7.3 Specification proposal May 2018 Visual Studio 2017 version 15.7 8.0 colspan="2" rowspan="7" Specification proposal September 2019 Visual Studio 2019 version 16.3 9.0 Specification proposal November 2020 Visual Studio 2019 version 16.8 10.0 Specification proposal November 2021 Visual Studio 2022 version 17.0 11.0 Specification proposal November 2022 Visual Studio 2022 version 17.4 12.0 Specification proposal November 2023 Visual Studio 2022 version 17.8 13.0 Specification proposal November 2024 Visual Studio 2022 version 17.12 14.0 Specification proposal November 2025 Visual Studio 2026 version 18.0

Syntax

The core syntax of the C# language is similar to that of other C-style languages such as C, Objective-C, C++ and Java, particularly:

Semicolons are used to denote the end of a statement. Curly brackets are used to group statements. Statements are commonly grouped into methods (functions), methods into classes, and classes into namespaces. Variables are assigned using an equals sign, but compared using two consecutive equals signs. Square brackets are used with arrays, both to declare them and to get a value at a given index in one of them. "class", "int" and "void" are used to define large-scale (usually main) program functions in scripts most of the time in C-style computer programming languages.

Distinguishing features

Some notable features of C# that distinguish it from C, C++, and Java where noted, are:

Portability By design, C# is the programming language that most directly reflects the underlying Common Language Infrastructure (CLI). Most of its intrinsic types correspond to value-types implemented by the CLI framework. However, the language specification does not state the code generation requirements of the compiler: that is, it does not state that a C# compiler must target a Common Language Runtime (CLR), or generate Common Intermediate Language (CIL), or generate any other specific format. Some C# compilers can also generate machine code like traditional compilers of Objective-C, C, C++, Assembly and Fortran.

Typing C# supports strongly, implicitly typed variable declarations with the keyword var, and implicitly typed arrays with the keyword new[] followed by a collection initializer.

Its type system is split into two families: Value types, like the built-in numeric types and user-defined structs, which are automatically handed over as copies when used as parameters, and reference types, including arrays, instances of classes, and strings, which only hand over a pointer to the respective object. Due to their special handling of the equality operator and their immutability, strings will nevertheless behave as if they were values, for all practical purposes. The programmer can even use them as case labels. Where necessary, value types will be boxed automatically.

C# supports a strict Boolean data type, bool. Statements that take conditions, such as while and if, require an expression of a type that evaluates to the true boolean value. While C++ also has a Boolean type, it can be freely converted to and from integers, and expressions such as if (a) require only that a is convertible to bool, allowing a to be an int, or a pointer. C# disallows this "integer meaning true or false" approach, on the grounds that forcing programmers to use expressions that return exactly bool can prevent certain types of programming mistakes such as if (a = b) (use of assignment = instead of equality ==).