Record types in C#.NET
What are Record Types in C#? Records in C# 9 provide a way to create immutable value types. The record keyword defines a record type like enums, structs, and classes. However, these other types of constructs, record types are designed to be immutable by default. When you define a record type with properties and methods, the compiler will ensure those properties can never change after they are created. Anatomy of Record Types in C# In C# 9, records are a new type that can replace classes and structs. Record structs are introduced in C# 10, allowing you to define records as value types. The difference between records and classes is that records utilize value-based equality. Records of the same type with similar specifications and similar values in all fields are equal. In C# 9, a record type is a lightweight, immutable data type (or lightweight class) with primarily read-only properties. A record type is thread-safe, and because it is immutable, you cannot change it after it is created