How to Use Records in C# — Part 2

Christ khodabakhshi
4 min readDec 6, 2023

C# 9 introduced records to the language, I have explained what a record is and how to use it in my previous article How to Use Records in C# — Part 1. If you don’t know what a record is, it’s a good idea to read Part 1 first to not leave something behind and to know what features we get with records.

C# 10 added further changes to enhance the usefulness of record types, albeit making them slightly more complex. However, I will clarify and simplify these changes in this article.

Changes to Records in C# 10

C# 10 broke the existing record type into two subcategories of record struct and record class, which means that now we have a new record struct type that is different than what we had in C# 9, and the old one is called record class.

In the same way, record (record class) came to enhance the class functionalities, now the record struct type came to add more or less the same functionalities to the struct type that we had in C#.

Record class will be a reference type object while record struct will make a value type instance. However, both of them follow the value-based equality implementation.

Syntax

So, If you want to create a record struct, you should do it like the following code.

--

--

Christ khodabakhshi

Software developer, dad, coffee fan, and keen on talking about business ideas and investments.