« Record » : différence entre les versions
De Banane Atomic
Aller à la navigationAller à la recherche
Aucun résumé des modifications |
|||
Ligne 4 : | Ligne 4 : | ||
= Definition = | = Definition = | ||
Built-in functionality for encapsulating immutable data.<br> | |||
C# 10 allows the {{boxx|record class}} syntax as a synonym to clarify a reference type, and {{boxx|record struct}} to define a value type. | |||
= Primary constructor = | = Primary constructor = |
Version du 9 août 2024 à 13:21
Links
Definition
Built-in functionality for encapsulating immutable data.
C# 10 allows the record class syntax as a synonym to clarify a reference type, and record struct to define a value type.
Primary constructor
When you declare a primary constructor on a record, the compiler generates public properties for the primary constructor parameters.
public record Person(string FirstName, string LastName); // with the generated properties it is equivalent to public record Person { public required string FirstName { get; init; } public required string LastName { get; init; } }; |