Records can be stored on a heap or a stack:
Depending on the choice as above, the compiler will transform the record into either a class or a struct (in a process called the lowering). Record is just s “sugar syntax” in .NET.
Records are useful when we’re dealing with classes that just carry information and do not have any logic/methods.
Printing an instance of a record by default prints its content. An instance of a class would print its type.
Records printing behavior may be overridden just like in a normal class.
Class instances (unless explicitly coded otherwise) will not be equal even if all properties have the same values. Equality is checked by reference.
In the case of records, an equality check compares the values of the properties.
Records may be copied (by value) with some changes to original values like this:
A bit similarly to JS, we can extract some values from records: