C# 9 - Record Types Introduction & Deep-Dive

C# 9 - Record Types Introduction & Deep-Dive

Record types are introduced in C# 9 to allow developers to write immutable reference types. Let's break it all down and see what record types are, how to implement them in C# 9, and why we should care about them.

Record types are immutable reference types that provide value semantics for equality. Don't worry - record types aren't as complicated as they sound. Let's break it all down and see what record types are, how to implement them in C# 9, and why we should care about them.

Record types are introduced in C# 9 to allow developers to write immutable reference types. It means that the properties of an instance of a reference type cannot change after its initialization.

If we want to change the value of an existing object's property, we need to create a new instance. It is possible to inherit from a record type.

Record Types offer the following features:

  • Immutability through read-only properties
  • A constructor with properties as arguments
  • Value-based equality checks
  • A textual representation (ToString)
  • A Deconstruct method

Record types are essentially a compiler feature. The developer writes a record type definition, and during compilation, the compiler generates a class based on a template.

Every situation where we could take advantage of one of the features record types provide is a potential use case for using record types instead of writing a class.

  • 00:00 Introduction
  • 00:33 Record Types Introduction
  • 01:47 Cloning a record type
  • 02:11 Record Types Inheritance
  • 02:59 Value-based Equality
  • 04:26 ToString Implementation
  • 05:28 Record Types Internals - Generated Code (Advanced)
  • 06:53 Record Types Features
  • 08:12 Alternative Syntax
  • 10:32 Alternative Syntax: Properties without init-setters
  • 11:00 Alternative Syntax: Properties with default-setters
  • 11:30 Alternative Syntax: Summary
  • 12:05 Record Types: Add custom methods
  • 12:33 Record Types: Use cases
  • 13:49 Record Types: Conclusion

csharp programming developer

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

How long does it take to develop/build an app?

This article covers A-Z about the mobile and web app development process and answers your question on how long does it take to develop/build an app.

Developer Career Path: To Become a Team Lead or Stay a Developer?

For a developer, becoming a team leader can be a trap or open up opportunities for creating software. Two years ago, when I was a developer, ... by Oleg Sklyarov, Fullstack Developer at Skyeng company

Tracking a Developer’s Journey From Documentation Visit

Measuring website activity provides only half the story. See how to best track the developer's journey and what funnel stages makes sense for API-first products

Offshore Software Development - Best Practices

To make the most out of the benefits of offshore software development, you should understand the crucial factors that affect offshore development.

Hire Ruby on Rails Developer | Hire RoR Developer

#1 Ruby on Rails development company. Hire Ruby on rails developer or a team to build secure, scalable and complex web solutions with a quick turnaround time.