C# 14 · Records, classes and pattern matching

Require properties at creation

Force callers to set a property, and make it settable only during initialization.

public class User
{
    public required string Email { get; init; }
    public string? Nickname { get; set; }
}

Official C# 14 documentation

More records, classes and pattern matching commands

All records, classes and pattern matching commands · C# 14 cheatsheet

Was this page helpful?