Top
image credit: Freepik

When to use classes, structs, or records in C#

February 15, 2024

Via: InfoWorld

Classes, structs, and records are fundamental concepts in C# programming. Each is a different kind of type, with different features, capabilities, and limitations. To make matters more confusing, they have features and characteristics in common.

Classes are reference types that provide support for useful object-oriented concepts such as encapsulation, inheritance, and polymorphism. Structs are value types that offer better performance but have limitations in terms of size and mutability. Records, which were introduced in C# 9, combine the best of both classes and structs, with support for immutability by default.

Read More on InfoWorld