"Example Primary Constructor on a Non-Record Class"

sealed class User(string name, int age) { // Notice the new syntax here, defining a primary ctor with a string "name" and int "age"
	// We define a single void method that uses the name and age parameters from the primary constructor
	public void PrintNameAndAge() { 
		Console.WriteLine($"User name: {name}, Age: {age}");
	}
}

// Usage:

static void Test() {
	var user = new User("Ben", 33);
	user.PrintNameAndAge(); // Prints "User name: Ben, Age: 33" to console
}


Code snippet taken from "Complete C# Quick Reference - C# 12".