What is Record in C#?
What is Record in C#?
A record in C#, introduced in C# 9.0, is a reference type that provides a concise way to define immutable data structures. Records are designed to make it easier to work with data-centric types, such as those used in data transfer objects (DTOs) or value objects.
Here are the key features of records in C#:
Records are immutable by default, meaning that once created, their properties cannot be changed. This helps prevent unintended modifications and promotes thread safety.
Records have a more concise syntax compared to traditional classes. They allow you to define properties directly in the record declaration, without the need for separate property declarations.
Records automatically implement value-based equality and comparison. Two records are considered equal if all their properties are equal. This behavior is defined by the IEquatable<T>
and IComparable<T>
inter...
middle
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào