How C# record class and record struct differ from standard classes:
public record User(int Id, string Username, string Email);Compiler-Synthesized Features:
- Value-Based Equality: Two record instances with identical property values compare equal (
user1 == user2istrue). - Non-Destructive Mutation (
withexpression):var updated = user with { Email = "new@domain.com" }; - Deconstruction:
var (id, name, email) = user; - Formatted ToString(): Automatically prints
User { Id = 1, Username = Alice, Email = ... }for clean logging.