Skip to content

C# 10

Many of these features are small individually, but together they noticeably improve readability.

Modernization Overview

File-scoped namespaces remove one level of indentation from every type in a file.

namespace MyApp.Services;
public sealed class OrderService
{
}

Legacy style:

namespace MyApp.Services
{
public sealed class OrderService
{
}
}

Global usings let a project declare common imports once.

global using System;
global using Microsoft.Extensions.Logging;

This is useful when the same namespaces appear across many files. It reduces repetition, but it should still be applied deliberately to avoid hiding dependencies too much.

Record structs bring record-style value semantics to struct types.

public readonly record struct Point(int X, int Y);

This is useful for small value objects where a struct is appropriate and value equality is desired.

Extended property patterns allow deeper navigation without extra nesting.

if (order is { Customer.Address.Country: "BE" })
{
Console.WriteLine("Belgium");
}

Legacy style often required multiple null checks or intermediate variables.

CallerArgumentExpression improves guard methods and validation helpers.

public static void NotNull<T>(T value,
[System.Runtime.CompilerServices.CallerArgumentExpression("value")] string? name = null)
where T : class
{
if (value is null)
throw new ArgumentNullException(name);
}

Usage:

NotNull(order);

The helper can still report "order" without the caller repeating that name manually.