C# 14 · Records, classes and pattern matching

Declare a class with a primary constructor

Put constructor parameters on the type declaration and use them in members.

public class Greeter(string name)
{
    public string Greet() => $"Hello, {name}!";
}

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?