Working with record types
As a developer, you wish to have immutability with reference types, especially while working on concurrent programming with shared data. To achieve immutability with reference types, we must write quite a bit of code. The record types introduced in C# 9.0 provide type declaration to create immutable reference types. They have synthesized methods for equality by comparing the equality of the properties, rather than comparing the hash code of the objects, unlike reference types. The following shows a declaration of a Shape
record type that holds the name of the shape:
public record Shape(string Name);
Build the project and open the library in a disassembly tool such as ILSpy or Reflector. You can install ILSpy from https://marketplace.visualstudio.com/items?itemName=SharpDevelopTeam.ILSpy. In ILSpy, we see the definition of the Shape
record type as shown in the following figure: