Skip to content
Tutorials Center
My learning

Topics

Lesson 93 of 182 ยท Pattern Matching and Modern C#

What's New in C# 8 to 14

A version-by-version tour of C# 8 to 14 with short runnable examples - nullable references, records, raw strings, primary constructors, collection expressions, the field keyword and extension members.

C# ships a new version every November, together with a new .NET release. Since C# 8 (2019) each version has added a handful of features, and together they have changed how idiomatic C# looks. Code written in 2018 is still valid, but a developer who last read C# then would find today's code compact and somewhat alien: no Main method, no constructors that just copy parameters, no new List<int>() { ... }.

This lesson is a guided tour. For each version you get the headline features, one or two runnable examples and a note on when to use them. It is a map, not a manual: most features have their own lessons, linked below. Everything here runs on C# 14 with .NET 10 (the long-term-support release shipped in November 2025), the version our editor uses.

How versions and runtimes fit together

Each C# version has a default .NET version, and the compiler picks the language version from the target framework: .NET 10 gives C# 14, .NET 9 gives C# 13, .NET 8 gives C# 12, .NET 6 gives C# 10, and so on. You can override it with <LangVersion> in the project file, but some features also need a newer runtime library (for example System.Threading.Lock is a .NET 9 type, so the C# 13 lock improvement needs .NET 9 or later).

Odd-numbered .NET releases get only 24 months of support, even-numbered ones (6, 8, 10) are LTS releases with three years. Most teams move from one LTS version to the next.

C# .NET Year Headline
8 Core 3.0 2019 Nullable reference types, async streams, ranges, switch expressions
9 5 2020 Records, init-only setters, top-level statements, target-typed new
10 6 2021 File-scoped namespaces, global usings, record structs
11 7 2022 Raw string literals, list patterns, required members
12 8 2023 Primary constructors, collection expressions
13 9 2024 params collections, Lock, partial properties
14 10 2025 Extension members, field keyword, null-conditional assignment

C# 8: safer and more expressive

C# 8 was the first version that did not run on the old .NET Framework in full, and it introduced the single biggest correctness feature of the decade.

C# C# 8 in one program

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

C# 9: records and less ceremony

C# 9 is where modern C# starts to look modern.

  • Records give value-based types in one line. See Records.
  • init accessors allow properties that are settable only during construction.
  • Top-level statements: no Program class or Main. See Program Structure.
  • Target-typed new: List<int> xs = new();
  • Relational and logical patterns (> 5, and, or, not).
  • Covariant return types, static anonymous functions, module initializers.
C# C# 9: records, init and target-typed new

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

C# 10: less boilerplate in every file

  • File-scoped namespaces (namespace MyApp;) remove one indent level from the whole file.
  • Global usings (global using System.Text;) and implicit usings from the SDK.
  • Record structs (record struct Point(int X, int Y)).
  • Extended property patterns ({ Address.City: "Oslo" }).
  • Lambda improvements: natural types and attributes, so var f = (int x) => x * 2; compiles.
  • CallerArgumentExpression, which the ArgumentNullException.ThrowIfNull helpers use to report the argument text.
  • Constant interpolated strings and with on structs and anonymous types.
C# C# 10: record struct, extended patterns, lambda natural type

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

C# 11: text and shape

  • Raw string literals ("""...""") hold quotes and backslashes without escaping. See Raw and Verbatim Strings.
  • List patterns. See List and Slice Patterns.
  • required members force callers to set a property in an initializer.
  • Generic math: static abstract interface members and interfaces like INumber<T>.
  • UTF-8 string literals ("text"u8) producing ReadOnlySpan<byte>.
  • File-local types (file class Helper), auto-default structs, scoped and newline-in-interpolation improvements.
C# C# 11: raw strings, required members, generic math

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

The raw string removes the common indentation, which is determined by the closing """. The same generic method sums both int and double because both implement INumber<T>. The UTF-8 literal is 6 bytes for 5 characters because รฉ takes two bytes.

C# 12: constructors and collections

  • Primary constructors on classes and structs (class Service(ILogger log)). See Primary Constructors.
  • Collection expressions ([1, 2, 3], spread ..). See Collection Expressions.
  • Default parameter values in lambdas, ref readonly parameters, alias any type (using Point = (int X, int Y);), inline arrays and the Experimental attribute.
C# C# 12: primary constructors, collection expressions, aliases

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

C# 13: params, locks and escapes

  • params collections: params works with Span<T>, ReadOnlySpan<T>, List<T> and other collection types, not only arrays, which avoids allocations.
  • System.Threading.Lock: a dedicated lock type; lock (myLock) on it uses the new, faster API.
  • \e escape for the ESC character (useful for ANSI colors).
  • Partial properties and indexers, which source generators use.
  • ^ index in object initializers, ref and unsafe in iterators and async methods, a new OverloadResolutionPriority attribute.
C# C# 13: params span, Lock and the escape character

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

C# 14: properties and extensions

C# 14 shipped with .NET 10 in November 2025. See C# 14 Features in Depth for details; here is the tour.

  • The field keyword inside property accessors refers to the compiler-generated backing field, so you can add logic to an auto-property without declaring a field.
  • Extension members: extension properties, static extension members and operators, in extension(Type receiver) { ... } blocks. See Extension Methods.
  • Null-conditional assignment: customer?.Name = "x" assigns only when customer is not null.
  • Implicit conversions between arrays, Span<T> and ReadOnlySpan<T>, partial constructors and events, lambda parameter modifiers without types ((out int x) => ...), unbound generic types in nameof, user-defined compound assignment operators.
C# C# 14: field, extension members, null-conditional assignment

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

Before C# 14 the Name property needed an explicit private field to trim on assignment. With field the accessor body stays tiny. The extension block adds a real property (WordCount) and a static member (string.Split2), neither possible with classic extension methods.

Features worth turning on in every project

You do not have to learn all of this at once. If you start a new project today, these give the most value for the least effort:

  1. Nullable reference types on (the default in new templates).
  2. File-scoped namespaces and implicit usings.
  3. Records for data and pattern matching for decisions.
  4. Collection expressions instead of constructor-plus-Add code.
  5. Primary constructors for dependency injection and simple types.
  6. Raw string literals for JSON, SQL and templates.

Upgrading safely

  • Language features usually require only a compiler change, so upgrading the SDK and <TargetFramework> is mostly safe, but read the breaking changes notes for each .NET release: behavior of library methods does change occasionally.
  • New warnings (nullable, analyzers) appear with new SDKs. Fix them rather than suppressing wholesale. TreatWarningsAsErrors is great in CI, painful during upgrades.
  • Use the <LangVersion> override only for experiments. Mixed language versions inside a team are a recipe for confusion.
  • Preview features (<LangVersion>preview</LangVersion>) can change or disappear; keep them out of shipping code.
  • Watch for contextual keywords that became real: field in C# 14 can clash with a field of that name in an existing property accessor, which is now interpreted as the keyword; rename the field or write @field / this.field.

Version numbers matter when you read old tutorials and Stack Overflow answers. An answer from 2017 that says "you cannot do X in C#" may be out of date. Check the date and the language version, and prefer the modern form.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Which C# version introduced records, init-only setters and top-level statements?

    All three arrived together in C# 9 with .NET 5. Primary constructors for classes came later in C# 12.
  2. 2. Which feature lets you write [1, 2, ..other] to build a List<int>?

    Collection expressions with the spread element arrived in C# 12. List patterns (C# 11) are for matching existing sequences, not for creating them.
  3. 3. What does the field keyword (C# 14) refer to inside a property accessor?

    field gives access to the synthesized backing field so you can add logic to an auto-property without declaring a field yourself.
  4. 4. What is the effect of customer?.Name = "x" when customer is null (C# 14)?

    Null-conditional assignment evaluates the right-hand side and assigns only when the receiver is not null; otherwise nothing happens and no exception is thrown.
  5. 5. Which LTS release of .NET ships with C# 14?

    C# 14 ships with .NET 10, released in November 2025 as a long-term-support release.

Summary

  • C# gets a new version each November, tied to a .NET release; the SDK picks the language version from the target framework.
  • C# 8: nullable references, async streams, ranges, switch expressions. C# 9: records, init, top-level statements. C# 10: file-scoped namespaces, global usings, record structs.
  • C# 11: raw strings, list patterns, required, generic math. C# 12: primary constructors, collection expressions. C# 13: params collections, Lock, \e.
  • C# 14 (with .NET 10): the field keyword, extension members, null-conditional assignment and more.
  • Adopt nullable references, records, patterns, collection expressions and raw strings first; upgrade LTS to LTS and fix new warnings instead of silencing them.

Next: C# 14 Features in Depth