C# 14 (2025): extension members, field and null-conditional set
What you’ll learn
Section titled “What you’ll learn”- What C# 14 added, which SDK and Visual Studio version it needs, and why it is the version many teams standardize on.
- How
extensionblocks add extension properties and static extension members. - How the
fieldkeyword works with nullable analysis, and when a named backing field is still better. - What null-conditional assignment skips, and how that can hide a bug.
- What first-class span conversions change in overload resolution, and why that can break expression trees and covariant arrays.
Summary
Section titled “Summary”C# 14 is the .NET 10 edition of the language: released, stable and paired with a Long Term Support runtime.
Release at a glance
Section titled “Release at a glance”| Item | Value |
|---|---|
| Released | November 2025 |
| Paired runtime | .NET 10 (LTS) |
| Minimum toolset | .NET 10 SDK; Visual Studio 2026 (no minimum update stated by Microsoft) |
| Default for TFM | net10.0 |
LangVersion |
14.0 (or 14) |
| Support today | Supported: .NET 10 is supported until November 14, 2028. Microsoft states that C# 14 “is supported only on .NET 10 and newer versions” |
| Previews in this release | None new; the field keyword, a C# 13 preview, is final here |
Feature map
Section titled “Feature map”| Feature | Weight | Mainly for | Deep dive |
|---|---|---|---|
| Extension members | Headline | Library and app code | Extension members |
field keyword |
Headline | App code | Field-backed properties |
| Null-conditional assignment | Headline | App code | Null-conditional assignment |
| Implicit span conversions | Smaller (with a breaking change) | Library code, performance | Implicit span conversions |
nameof with unbound generic types |
Smaller | App code | nameof with unbound generics |
| Modifiers on simple lambda parameters | Smaller | App code | Lambda parameter modifiers |
| User-defined compound assignment | Smaller | Library code, performance | User-defined compound assignment |
| Partial constructors and events | Smaller | Source generators | Partial constructors, partial events |
| File-based apps (.NET 10 SDK) | Tooling | Scripts | File-based app directives |
How to run the samples
Section titled “How to run the samples”Create a console app with dotnet new console using the .NET 10 SDK, replace Program.cs with the sample, and keep the default implicit using directives and <Nullable>enable</Nullable>. The samples were compiled with the compiler in .NET SDK 10.0.115 using -langversion:14.0 and run on .NET 10.0.15; samples that print numbers set the invariant culture. Output is shown under each sample.
Headline feature: extension members
Section titled “Headline feature: extension members”Problem
Section titled “Problem”Extension methods (C# 3) could only add instance-style methods. You couldn’t add a property such as list.IsEmpty, a static helper that reads like string.IsBlank(...), or an operator to a type you don’t own.
How it works
Section titled “How it works”An extension block inside a static class names a receiver. Members in a block with a named receiver parameter, such as extension(IReadOnlyList<int> values), are called like instance members. Members in a block with only a receiver type, such as extension(string), are called like static members of that type. Blocks can contain methods, properties and user-defined operators, and existing this-parameter extension methods keep working unchanged.
Example
Section titled “Example”using System.Diagnostics.CodeAnalysis;using System.Globalization;
CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
List<int> noOrders = [];List<int> basketSizes = [3, 9, 5, 4];
Console.WriteLine(noOrders.IsEmpty); // instance extension propertyConsole.WriteLine(basketSizes.Median); // extension property with logicConsole.WriteLine(string.IsBlank(" ")); // static extension member on string
public static class OrderExtensions{ extension<T>(IReadOnlyCollection<T> source) { public bool IsEmpty => source.Count == 0; }
extension(IReadOnlyList<int> values) { public double Median { get { if (values.Count == 0) throw new InvalidOperationException("No values."); var sorted = values.Order().ToArray(); int mid = sorted.Length / 2; return sorted.Length % 2 == 1 ? sorted[mid] : (sorted[mid - 1] + sorted[mid]) / 2.0; } } }
// Receiver type only (no parameter name): members become static members of 'string'. extension(string) { public static bool IsBlank([NotNullWhen(false)] string? text) => string.IsNullOrWhiteSpace(text); }}Output:
True4.5TrueGotchas
Section titled “Gotchas”- No state. Extension properties have no backing field. A property that does expensive work, like sorting in
Median, looks cheap at the call site. - Real members win silently. A member declared on the type takes precedence over an extension with the same signature. If a library later adds
IsEmpty, your extension stops being called without any warning. - Scope is the namespace. Extensions apply wherever their namespace is imported, including through global usings.
When not to use it
Section titled “When not to use it”Use a method, not a property, when the work isn’t cheap. Don’t use static extension members to make a type look as if it owns behavior that belongs to your domain; a normal static class is easier to find.
Headline feature: the field keyword
Section titled “Headline feature: the field keyword”Problem
Section titled “Problem”Adding one line of validation or normalization to an auto-property meant declaring a backing field and writing both accessors.
How it works
Section titled “How it works”Inside a property accessor, field refers to a compiler-synthesized backing field. You can write a body for one accessor and keep the other automatic, and you can still use a property initializer. Nullable analysis treats the synthesized field specially: if the getter returns a non-null value even when the field is null, as in field ??= ..., the property is “null-resilient” and the compiler treats the backing field as nullable, so a lazily initialized non-nullable property gets no “uninitialized” warning.
Example
Section titled “Example”var account = new Account { Email = " Ada@Example.TEST " };Console.WriteLine(account.Email);Console.WriteLine(account.DisplayName); // computed once, on first read
try{ account.Email = "not-an-email";}catch (ArgumentException ex){ Console.WriteLine(ex.Message);}
class Account{ // 'field' is the compiler-synthesized backing field: validation without a declared field. public string Email { get; set { string normalized = value.Trim().ToLowerInvariant(); field = normalized.Contains('@') ? normalized : throw new ArgumentException("Email must contain '@'.", nameof(value)); } } = "";
// Lazy initialization: the getter never returns null, so the compiler treats the // backing field as nullable and gives no "uninitialized property" warning. public string DisplayName => field ??= Email.Split('@')[0];}Output:
ada@example.testadaEmail must contain '@'. (Parameter 'value')Gotchas
Section titled “Gotchas”- Name clashes. If the type already has a member named
field, the keyword shadows it inside accessors, with “warning CS9258: In language version 14.0, the ‘field’ keyword binds to a synthesized backing field for the property.” Use@fieldorthis.field, or rename the member. - Mixing storage. Using
fieldin one accessor and an explicit field in the other produces CS9266, because the two accessors would read and write different storage. - Nullability mismatches. When the analysis can’t infer that a non-nullable property tolerates a null field, you get CS9264; add
[field: MaybeNull, AllowNull], make the property nullable or initialize it. - Caching is per instance and not thread-safe.
field ??= ...can run the initializer twice under concurrency; useLazy<T>when that matters.
When not to use it
Section titled “When not to use it”Keep a named backing field when other members must read or reset it (for example, a Reset() method that clears a cache), when serializers or [field: ...] attributes would become hard to read, or when the backing storage isn’t the same type as the property.
Headline feature: null-conditional assignment
Section titled “Headline feature: null-conditional assignment”Problem
Section titled “Problem”Assigning through a reference that might be null took an if statement around every assignment.
How it works
Section titled “How it works”?. and ?[] can appear on the left side of = and compound assignments such as +=. The receiver is evaluated once; if it is null, the whole assignment is skipped, including the right-hand side. Increment and decrement aren’t allowed: c?.X++ fails with CS1059.
Example
Section titled “Example”var missing = OrderStore.Find("ORD-404");missing?.Status = OrderStore.LoadStatus(); // right side not evaluated: missing is nullConsole.WriteLine($"status loads after null: {OrderStore.StatusLoads}");
var order = OrderStore.Find("ORD-1");order?.Status = OrderStore.LoadStatus();order?.Reminders += 1; // compound assignment works tooConsole.WriteLine($"status loads: {OrderStore.StatusLoads}, reminders: {order?.Reminders}");
class Order{ public string Status { get; set; } = "new"; public int Reminders { get; set; }}
static class OrderStore{ public static int StatusLoads { get; private set; }
public static Order? Find(string id) => id == "ORD-1" ? new Order() : null;
public static string LoadStatus() { StatusLoads++; return "shipped"; }}Output:
status loads after null: 0status loads: 1, reminders: 1Gotchas
Section titled “Gotchas”- Silent skips hide bugs. If
orderis null because of a bug (a wrong ID, a failed lookup),order?.Status = "shipped"does nothing and the order is never marked shipped. ANullReferenceExceptionwould at least have told you. - Side effects disappear. Because the right side isn’t evaluated, a call such as
LoadStatus()that also logs, counts or reserves stock doesn’t run.
When not to use it
Section titled “When not to use it”Use it only where “no receiver, no update” is the intended business rule, such as an optional UI element. When the receiver must exist, check it explicitly and throw or log, so the null surfaces instead of being swallowed.
Smaller changes
Section titled “Smaller changes”using System.Globalization;
CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
// nameof with an unbound generic type: log the collection kind without a fake type argument.Console.WriteLine(nameof(List<>));Console.WriteLine(nameof(Dictionary<,>));
// Lambda parameter modifier without a type: parse quantities from an import file.TryParse<int> parseQuantity = (text, out result) => int.TryParse(text, out result);Console.WriteLine(parseQuantity("42", out var quantity) && quantity == 42);
// Implicit span conversion: int[] becomes ReadOnlySpan<int> as an extension receiver.int[] orderIds = [1001, 1002, 1003];Console.WriteLine(orderIds.StartsWith(1001));
// User-defined instance compound assignment and increment: a running total mutated in place.var dailyTotal = new RunningTotal(10m);dailyTotal += new RunningTotal(5m);dailyTotal++;Console.WriteLine(dailyTotal.Amount);
// Partial constructor and event: an import job whose plumbing a source generator would emit.var job = new ImportJob("orders.csv");job.Completed += (_, file) => Console.WriteLine($"imported: {file}");job.Run();
delegate bool TryParse<T>(string text, out T result);
class RunningTotal(decimal amount){ public decimal Amount { get; private set; } = amount;
public void operator +=(RunningTotal other) => Amount += other.Amount; public void operator ++() => Amount += 1m;}
// Defining declarations (what you write for a source generator)...partial class ImportJob{ public partial ImportJob(string file); public partial event EventHandler<string>? Completed;}
// ...implementing declarations (what the generator would emit).partial class ImportJob{ private readonly string _file; private EventHandler<string>? _completed;
public partial ImportJob(string file) => _file = file;
public partial event EventHandler<string>? Completed { add => _completed += value; remove => _completed -= value; }
public void Run() => _completed?.Invoke(this, _file);}Output:
ListDictionaryTrueTrue16imported: orders.csvnameofwith unbound generic types:nameof(List<>)returnsList; before C# 14 you had to write a closed type such asnameof(List<int>).- Modifiers on simple lambda parameters:
scoped,ref,in,outandref readonlywork without parameter types.paramsstill needs an explicitly typed list. - Implicit span conversions: arrays convert to
Span<T>andReadOnlySpan<T>,Span<T>toReadOnlySpan<T>, andstringtoReadOnlySpan<char>, including for extension receivers and generic type inference. That is whyorderIds.StartsWith(1001)binds toMemoryExtensions.StartsWith. The side effects are in Breaking changes. - User-defined compound assignment: instance
operator +=andoperator ++mutate in place, which avoids an allocation per+=for large mutable types. Don’t add them to immutable types. - Partial constructors and events: each needs exactly one defining and one implementing declaration; only the implementing constructor can have a
this()orbase()initializer, and the implementing event needsaddandremove.
File-based apps
Section titled “File-based apps”The .NET 10 SDK, which ships C# 14, runs a single .cs file without a project: dotnet run report.cs. Directives at the top of the file, such as #:package, #:property and #:sdk, replace project settings; the SDK reads them and the compiler ignores them. Use them for scripts and experiments, and convert to a project when a script grows several files or needs tests; dotnet publish of a file-based app targets native AOT by default. See File-based app directives for the directive list.
Breaking changes
Section titled “Breaking changes”Span overloads bind in more places. This is the one mechanism behind most C# 14 upgrade breaks. The new implicit conversions make methods with Span<T> or ReadOnlySpan<T> parameters applicable where only IEnumerable<T> overloads applied before, and overload resolution prefers them. Three consequences follow:
- Expression trees. Inside an
Expression<...>lambda,array.Contains(x)now binds toMemoryExtensions.Containsinstead ofEnumerable.Contains. Expression trees compiled with interpretation fail at run time with ref struct values, and query providers that expectEnumerable.Containsmay not translate the call. Microsoft’s recommended fix is to callEnumerable.Contains(array, x)explicitly or cast arguments to the exact parameter types. - Covariant arrays. A
string[]stored in anobject[]variable converts toSpan<object>only by throwingArrayTypeMismatchException, because writes through the span could store a non-string. When aSpan<T>overload is chosen where anIEnumerable<T>overload used to be, that exception appears at run time. Overload resolution therefore prefersReadOnlySpan<T>overSpan<T>, which can itself cause new ambiguities. - New ambiguities and different overloads, for example in test assertion libraries with both array and span overloads. Use
.AsSpan(),.AsEnumerable()or an explicit static call to pick one.
object[] labels = new string[] { "gift", "express" }; // array covariance: legal since C# 1try{ Span<object> view = labels; // C# 14: implicit array-to-span conversion Console.WriteLine(view.Length);}catch (ArrayTypeMismatchException){ Console.WriteLine("ArrayTypeMismatchException");}ReadOnlySpan<object> readOnlyView = labels; // read-only spans are safe hereConsole.WriteLine(readOnlyView.Length);Output:
ArrayTypeMismatchException2field inside accessors now means the synthesized backing field (CS9258 when a member named field exists).
Upgrade steps and gotchas
Section titled “Upgrade steps and gotchas”- Retarget to
net10.0. That selects C# 14 by default; don’t setLangVersiontolatest. - Run the tests for LINQ providers and mocking setups that inspect expression trees. Search for
Contains,SequenceEqualand similar calls on arrays inside lambdas passed asExpression<...>. - Search for covariant array use (arrays of a derived type stored in base-type array variables) passed to methods that gained span overloads.
- Fix CS9258 warnings from members named
field. - Adopt extension blocks gradually. Existing extension methods don’t need rewriting.
Where it sits in the language’s evolution
Section titled “Where it sits in the language’s evolution”Extension members are the largest change to extensions since C# 3, and C# 15 extended them again with extension indexers. The field keyword finished a long-requested feature that previewed in C# 13. Implicit span conversions complete the span work that started with Span<T> in C# 7.2 and continued through params spans in C# 13.
Interview questions
Section titled “Interview questions”What is the difference between extension(IReadOnlyCollection<T> source) and extension(string)?
With a named receiver, members are called like instance members on a value: noOrders.IsEmpty. With only a receiver type, members are called like static members of that type: string.IsBlank(text).
What does missing?.Status = LoadStatus(); do when missing is null, and why can that be dangerous?
It skips the whole assignment, so LoadStatus() isn’t called. If the null is a bug, the update and any side effects of the right-hand side silently disappear.
Why can C# 14 turn working code into an ArrayTypeMismatchException?
Array covariance lets a string[] sit in an object[] variable. When a newly applicable Span<object> overload is chosen instead of an IEnumerable<object> one, converting the array to a writable span throws, because the span could be used to store a non-string. ReadOnlySpan<T> overloads, which the compiler now prefers, don’t have this problem.
When would you keep an explicit backing field instead of field?
When another member must read or reset the storage, when the storage type differs from the property type, or when attributes on the field would be clearer on a named declaration.
Senior scenario: your team wants to replace a large set of static helper classes with extension members. What rules do you set? Use extension properties only for cheap, side-effect-free values. Choose names that are unlikely to collide with future members of the extended type, because a real member wins silently. Keep extensions in clearly named namespaces so they don’t leak into every file through global usings, and leave existing extension methods alone unless the new form clearly reads better.
Key takeaways
Section titled “Key takeaways”- C# 14 is the .NET 10 (LTS) language version and the oldest pairing still in support.
extensionblocks add extension properties, static extension members and operators.- The
fieldkeyword removes declared backing fields and works with nullable analysis for lazy properties. - Null-conditional assignment skips the right side when the receiver is null; don’t use it where null is a bug.
- Implicit span conversions make span overloads bind more often, which can break expression trees and covariant-array code.
Related pages
Section titled “Related pages”- C# versions: release history and guides
- Extension members
- Field-backed properties
- Null-conditional assignment
- Implicit span conversions
- File-based app directives
- C# 13 (2024) and C# 15 (2026)
Official release notes
Section titled “Official release notes”- What’s new in C# 14
- The history of C#: C# version 14
- Feature specification: first-class span types
- Feature specification: the field keyword (nullability)
- Errors and warnings for field-backed properties
- C# 14 overload resolution with span parameters (.NET 10 breaking change)
- Compiler breaking changes from .NET 9.0.100 to .NET 10.0.100
- Preprocessor directives for file-based apps
- Releases and support for .NET