Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This article provides a history of each major release of the C# language. The C# team is continuing to innovate and add new features. Detailed language feature status, including features considered for upcoming releases can be found on the dotnet/roslyn repository on GitHub. To find when a particular feature was added to the language, consult the C# version history file in the dotnet/csharplang repository on GitHub.
Important
The C# language relies on types and methods in what the C# specification defines as a standard library for some of the features. The .NET platform delivers those types and methods in a number of packages. One example is exception processing. Every throw statement or expression is checked to ensure the object being thrown is derived from Exception. Similarly, every catch is checked to ensure that the type being caught is derived from Exception. Each version may add new requirements. To use the latest language features in older environments, you may need to install specific libraries. These dependencies are documented in the page for each specific version. You can learn more about the relationships between language and library for background on this dependency.
C# version 13
Released November 2024
C# 13 includes the following new features:
paramscollections: theparamsmodifier isn't limited to array types. You can now useparamswith any recognized collection type, includingSpan<T>, and interface types.- New
locktype and semantics: If the target of alockstatement is a System.Threading.Lock, compiler generates code to use the Lock.EnterScope() method to enter an exclusive scope. Theref structreturned from that supports theDispose()pattern to exit the exclusive scope. - New escape sequence -
\e: You can use\eas a character literal escape sequence for theESCAPEcharacter, UnicodeU+001B. - Small optimizations to overload resolution involving method groups.
- Implicit indexer access in object initializers: The implicit "from the end" index operator,
^, is now allowed in an object initializer expression. - You can use
reflocals andunsafecontexts in iterators and async methods. - You can use
ref structtypes to implement interfaces. - You can allow
ref structtypes as arguments for type parameters in generics. - Partial properties and indexers are now allowed in
partialtypes. - Overload resolution priority allows library authors to designate one overload as better than others.
And, the field contextual keyword to access the compiler generated backing field in an automatically implemented property was released as a preview feature.
C# version 12
Released November 2023
The following features were added in C# 12:
- Primary constructors - You can create primary constructors in any
classorstructtype. - Collection expressions - A new syntax to specify collection expressions, including the spread element, (
..e), to expand any collection. - Inline arrays - Inline arrays enable you to create an array of fixed size in a
structtype. - Optional parameters in lambda expressions - You can define default values for parameters on lambda expressions.
ref readonlyparameters -ref readonlyparameters enables more clarity for APIs that might be usingrefparameters orinparameters.- Alias any type - You can use the
usingalias directive to alias any type, not just named types. - Experimental attribute - Indicate an experimental feature.
And, Interceptors - was released as a Preview feature.
Overall, C# 12 provides new features that make you more productive writing C# code. Syntax you already knew is available in more places. Other syntax enables consistency for related concepts.
C# version 11
Released November 2022
The following features were added in C# 11:
- Raw string literals
- Generic math support
- Generic attributes
- UTF-8 string literals
- Newlines in string interpolation expressions
- List patterns
- File-local types
- Required members
- Auto-default structs
- Pattern match
Span<char>on a constantstring - Extended
nameofscope - Numeric IntPtr
reffields andscoped ref- Improved method group conversion to delegate
- Warning wave 7
C# 11 introduces generic math and several features that support that goal. You can write numeric algorithms once for all number types. There's more features to make working with struct types easier, like required members and auto-default structs. Working with strings gets easier with Raw string literals, newline in string interpolations, and UTF-8 string literals. Features like file local types enable source generators to be simpler. Finally, list patterns add more support for pattern matching.
C# version 10
Released November 2021
C# 10 adds the following features and enhancements to the C# language:
- Record structs
- Improvements of structure types
- Interpolated string handlers
global usingdirectives- File-scoped namespace declaration
- Extended property patterns
- Lambda expressions can have a natural type, where the compiler can infer a delegate type from the lambda expression or method group.
- Lambda expressions can declare a return type when the compiler can't infer it.
- Attributes can be applied to lambda expressions.
- In C# 10,
conststrings can be initialized using string interpolation if all the placeholders are themselves constant strings. - In C# 10, you can add the
sealedmodifier when you overrideToStringin a record type. - Warnings for definite assignment and null-state analysis are more accurate.
- Allow both assignment and declaration in the same deconstruction.
- Allow
AsyncMethodBuilderattribute on methods - CallerArgumentExpression attribute
- C# 10 supports a new format for the
#linepragma.
More features were available in preview mode. In order to use these features, you must set <LangVersion> to Preview in your project:
- Generic attributes later in this article.
- static abstract members in interfaces.
C# 10 continues work on themes of removing ceremony, separating data from algorithms, and improved performance for the .NET Runtime.
Many of the features mean you type less code to express the same concepts. Record structs synthesize many of the same methods that record classes do. Structs and anonymous types support with expressions. Global using directives and file scoped namespace declarations mean you express dependencies and namespace organization more clearly. Lambda improvements make it easier to declare lambda expressions where they're used. New property patterns and deconstruction improvements create more concise code.
The new interpolated string handlers and AsyncMethodBuilder behavior can improve performance. These language features were applied in the .NET Runtime to achieve performance improvements in .NET 6.
C# 10 also marks more of a shift to the yearly cadence for .NET releases. Because not every feature can be completed in a yearly timeframe, you can try a couple of "preview" features in C# 10. Both generic attributes and static abstract members in interfaces can be used, but these preview features might change before their final release.
C# version 9
Released November 2020
C# 9 was released with .NET 5. It's the default language version for any assembly that targets the .NET 5 release. It contains the following new and enhanced features:
- Records
- Init only setters
- Top-level statements
- Pattern matching enhancements: relational patterns and logical patterns