[17] The principal inventors of the C# programming language were Anders Hejlsberg, Scott Wiltamuth, and Peter Golde from Microsoft.
Four years later, in 2004, a free and open-source project called Microsoft Mono began, providing a cross-platform compiler and runtime environment for the C# programming language.
As of January 2025,[update] the most recent stable version of the language is C# 13.0, which was released in 2024 in .NET 9.0[18][19] The Ecma standard lists these design goals for C#:[17] During the development of the .NET Framework, the class libraries were originally written using a managed code compiler system named Simple Managed C (SMC).
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 had been ported to C#.
C# makes use of reification to provide "first-class" generic objects that can be used like any other class, with code generation performed at class-load time.
The LINQ extensions and the functional imports help developers reduce the amount of boilerplate code that is included in common tasks like 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.
[70] Most of its intrinsic types correspond to value-types implemented by the CLI (Common Language Infrastructure) framework.
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.
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 ==).
[79] As in other syntactically similar languages, such as C++ and ANSI C, the signature of a method is a declaration comprising in order: any optional accessibility keywords (such as private), the explicit specification of its return type (such as int, or the keyword void if no value is returned), the name of the method, and finally, a parenthesized sequence of comma-separated parameter specifications, each consisting of a parameter's type, its formal name and optionally, a default value to be used whenever none is provided.
[82] Like C++, and unlike Java, C# programmers must use the scope modifier keyword virtual to allow methods to be overridden by subclasses.
Like the Qt framework's pseudo-C++ signal and slot, C# has semantics specifically surrounding publish-subscribe style events, though C# uses delegates to do so.
[82] Since C# 3.0 the syntactic sugar of auto-implemented properties is available,[86] where the accessor (getter) and mutator (setter) encapsulate operations on a single field of a class.
The syntax for handling exceptions is the following:Most of the time people call this a "try-catch" code block, because of the "try" and "catch" functions being used and accessible on all C# versions.Depending on your plans, the "finally" part can be left out.
This was a design decision by the language's lead architect to avoid complications and to simplify architectural requirements throughout CLI.
A developer can query a variety of data sources, provided the IEnumerable
[96] Using LINQ in C# brings advantages like IntelliSense support, strong filtering capabilities, type safety with compile error checking ability, and consistency for querying data over a variety of sources.
[99] Though primarily an imperative language, C# always adds functional features over time,[100][101] for example: C# has a unified type system.
Examples of value types are all primitive types, such as int (a signed 32-bit integer), float (a 32-bit IEEE floating-point number), char (a 16-bit Unicode code unit), decimal (fixed-point numbers useful for handling currency amounts), and System.DateTime (identifies a specific point in time with nanosecond precision).
Nevertheless, specific reference types can provide such services by exposing a public constructor or implementing a corresponding interface (such as ICloneable or IComparable).
The following is a very simple C# program, a version of the classic "Hello world" example using the top-level statements feature introduced in C# 9:[111] For code written as C# 8 or lower, the entry point logic of a program must be written in a Main method inside a type: This code will display this text in the console window: Each line has a purpose: The above line imports all types in the System namespace.
To avoid that irresolvable circular dependency, C# compilers processing console applications (like that above) report an error if there is no static Main method.
(Note, however, that short programs can be written using Top Level Statements introduced in C# 9, as mentioned earlier.)
In the absence of generics, developers had to use collections such as ArrayList to store elements as objects of unspecified kind, which incurred performance overhead when boxing/unboxing/type-checking the contained items.
This shift is particularly important in the context of converting legacy systems, where updating to generics can significantly enhance performance and maintainability by replacing outdated data structures with more efficient, type-safe alternatives.
[113] Example In August 2001, Microsoft, Hewlett-Packard and Intel co-sponsored the submission of specifications for C# as well as the Common Language Infrastructure (CLI) to the standards organization Ecma International.
Additions included partial classes, anonymous methods, nullable types, and generics (somewhat similar to C++ templates).
Microsoft initially agreed not to sue open-source developers for violating patents in non-profit projects for the part of the framework that is covered by the Open Specification Promise.
[117] Microsoft also made a specific agreement not to enforce patent rights related to the Moonlight browser plugin, which depends on Mono, provided it is obtained through Novell.
[118] A decade later, Microsoft began developing free, open-source, and cross-platform tooling for C#, namely Visual Studio Code, .NET Core, and Roslyn.