Câu hỏi phỏng vấn C#
Câu hỏi

When to use Record vs Class vs Struct in C#?

Câu trả lời

Here is a concise answer to the interview question "When to use Record vs Class vs Struct in C#?":

Use a struct when you need a lightweight value type that is small, immutable, and has no complex behavior. Structs are stored on the stack and are passed by value, so they are ideal for small data structures that represent a single value, like points, colors, or key-value pairs[1][3].

Use a class when you need a reference type that supports inheritance, polymorphism, and complex behavior. Classes are more flexible than structs and can represent more complex entities, but they are stored on the heap and passed by reference, so they have more overhead[1][3].

Use a record when you need an immutable reference type that provides built-in value-based equality and concise syntax for creating data-centric types. Records are similar to cla...

middle

middle

Gợi ý câu hỏi phỏng vấn

senior

Explain the difference between Select and Where

middle

What is the use of Null Coalescing Operator ( ?? ) in C#?

junior

What are dynamic type variables in C#?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào