Language-Version-History.md
field keyword in properties: field allows access to the property's backing field without having to declare it.public void operator +=(int x)).Span types: streamlines usage of Span-based APIs by improving type inference and overload resolution.a?.b or a?[b] expression (a?.b = c).nameof: relaxes some restrictions on usage of generic types inside nameof (nameof(List<>)).(ref entry) => ...).#: directive prefix to be used by dotnet run app.cs tooling but ignored by the language.Expression trees: relaxes some restrictions on Expression trees (Expression<...> e = (a, i) => a.Contains(i, comparer: null);).\e escape sequence to represent the ESCAPE/ESC character (U+001B).Lock object: allow performing a lock on System.Threading.Lock instances.new C { [^1] = 2 }).params collections: extends params support to collection types (void M(params ReadOnlySpan<int> s)).ref/unsafe in iterators/async: allows using ref/ref struct locals and unsafe blocks in iterators and async methods between suspension points.ref struct interfaces: allows ref struct types to implement interfaces and introduces the allows ref struct constraint.System.Runtime.CompilerServices.OverloadResolutionPriority.partial modifier.List<int> list = [1, 2, 3];)class Point(int x, int y);)[InlineArray(size)] attribute.using alias declarations, allowing built-in types, tuple types, pointer types, array types (using Point = (int x, int y);)ref readonly parameters mandate that arguments are passed by reference instead of potentially copied, can’t be modified, and warn if a temporary variable must be created.nameof (nameof(field.ToString))(int i = 42) => { })var json = """{ "summary": "text" }"""; or var json = $$"""{ "summary": "text", "length": {{length}} }""";).u8 suffix (ReadOnlySpan<byte> s = "hello"u8;)Span<char> on a constant string: an input value of type Span<char> or ReadonlySpan<char> can be matched with a constant string pattern (span is "123").list is [1, 2, ..]).file type modifier (file class C { ... }).ref field declarations in a ref struct (ref struct S { ref int field; ... }), introduces scoped modifier and [UnscopedRef] attribute.required field and property modifier and [SetsRequiredMembers] attribute.>>> operator and >>>=.checked user-defined operators: numeric and conversion operators support defining checked variants (public static Int128 operator checked +(Int128 lhs, Int128 rhs) { ... }).intnint/nuint become simple types aliasing System.IntPtr/System.UIntPtr.[MyAttribute<int>]).nameof scope in attributes: allows nameof(parameter) inside an attribute on a method or parameter ([MyAttribute(nameof(parameter))] void M(int parameter) { }).record struct Point(int X, int Y);, var newPoint = point with { X = 100 };).global using directives avoid repeating the same using directives across many files in your program.dictionary?.TryGetValue(key, out value) == true.if (e is MethodCallExpression { Method.Name: "MethodName" })).ToString.(existingLocal, var declaredLocal) = expression).async method can be overridden locally.#line directives that specify the destination span (#line (startLine, startChar) - (endLine, endChar) charOffset "fileName").var f = short () => 1;).namespace X.Y.Z;).with expressions: succinctly declare reference types with value semantics (record Point(int X, int Y);, var newPoint = point with { X = 100 };).int Property { get; init; }).Main method.is < 30), combinator patterns (is >= 0 and <= 100, case 3 or 4:, is not null), parenthesized patterns (is int and (< 0 or > 100)), type patterns (case Type:).nint and nuint match the platform memory size.ldftn and calli (delegate* <int, void> local;)localsinit flag: attributing a method with [SkipLocalsInit] will suppress emitting the localsinit flag to reduce cost of zero-initialization.Point p = new(42, 43);.this or local variables (static () => { ... };).int? x = b ? 1 : null;)._ appearing in a lambda are allowed and are discards.[ModuleInitializer] will be executed before any other code in the assembly.GetEnumerator: an extension GetEnumerator method can be used in a foreach.void and use out parameters, but must be implemented.?, notnull constraint and annotations attributes in APIs, the compiler will use those to try and detect possible null values being dereferenced or passed to unsuitable APIs.await foreach and await using allow for asynchronous enumeration and disposal of IAsyncEnumerable<T> collections and IAsyncDisposable resources, and async-iterator methods allow convenient implementation of such asynchronous streams.using declaration is added with an implicit scope and using statements and declarations allow disposal of ref structs using a pattern.i..j syntax allows constructing System.Range instances, the ^k syntax allows constructing System.Index instances, and those can be used to index/slice collections.??= allows conditionally assigning when the value is null.static cannot capture this or local variables, and local function parameters now shadow locals in parent scopes.unmanaged constraint).readonly to indicate and enforce that they do not modify instance state.stackalloc expressions are now allowed in more expression contexts.@$"..." strings are recognized as interpolated verbatim strings just like $@"...".t is null on unconstrained type parameterSystem.Enum, System.Delegate and unmanaged constraints.= ref).Span<int> x = stackalloc[] { 1, 2, 3 };.fixed statement: Types that implement a suitable GetPinnableReference can be used in a fixed statement.out var and pattern variables are allowed in field initializers, constructor initializers and LINQ queries.== and !=.[field: …] attributes on an auto-implemented property to target its backing field.params arrays