What are record types in C# and how they ACTUALLY work

preview_player
Показать описание
Use discount code YTDEP2 at checkout for 15% off

Hello everybody I'm Nick and in this video I will talk about the record type that was added in C# 9. Records are great and they have many usecases but in this video we are going to focus on their features and also how they made their way into the language without having to change the runtime.

Intro - 0:00
Record features - 1:37
What records are behind the scenes - 10:12

Don't forget to comment, like and subscribe :)

Social Media:

#csharp #dotnet #records
Рекомендации по теме
Комментарии
Автор

I've been coding in C# for 20 years and I still learn a lot from your YouTube channel. Thanks Nick!

ExpensivePizza
Автор

More specifically, records use the synthesis part of the lowering process. All these members are called synthesized, and it's common among the most widely adopted features of the language, including auto-properties. The compiler synthesizes those members for our convenience of not needing to write the same boilerplate code everywhere. Then, those synthesized parts are lowered into the more primitive constructs the compiler would like to care about when compiling into IL.

Examples of other synthesized members include:
- async/await methods (using iterators)
- IEnumerable<T> methods using yield (yield iterators)
- records, as shown
- auto-properties (using the backing field)

AlFasGD
Автор

Been writing a C# for 5+ years now but I'm still impressed how Nick knows all these syntax tricks. For example, I never used "with" keyword, seems awesome though! Not mentioning the record types itself

damiank
Автор

Records also serialize/deserialze very neatly. One issue I've had with using classes for this is the need for an empty constructor for HTTP request bodies. Essentially forcing the objects to be mutable. But with records you can have the best of both worlds. As in, enforce immutability with specific constructors while allowing for JSON serialization.

buriedstpatrick
Автор

14:07 "From record to this monster..." Like it! ;-)

mabakay
Автор

I am a senior backend developer that has 80% or more of personal experience on Java. I have had a freelance job NetCore doing some basic projects on it and decided to take a full time job on c# and increase my knowledge. Your videos have been both very educative and surprisingly interesting and amusing! I had to thank you Nick. Happy new year! Hop you will keep on delivering this great quality content!

TheBdc
Автор

Thank you for this. I really didn't understand why record was added. Now, I see that is provided additional features but not in a more efficient way. So I would only use it if I really wanted the syntactic sugar it provides.

responsibleparty
Автор

I was convinced that record types were structures. Now it's more clear. Thanks for the video Nick!

MrJeeoSoft
Автор

Hi Nick, I'm from Venezuela, and one of the things for that I watch your videos is because I can totally understand you even though english isn't my native language.

CeleChaudary
Автор

I knew that there is one man on the internet who can answer my questions, so I wrote "Nick Chapsas Records" in the search bar and I didn't get disappointed ! Thank you for so many contents on so many details/subjects !

poniatowskimaximilian
Автор

Ok, from now number 69 is a Nick's trademark

NameSurname-zmgl
Автор

using with was amazing, you're a genius

odeyjoshuasunday
Автор

Interesting video. I'm wondering what are the ideal use cases for using record instead of simple classes. Dtos? Anything else?

rmdg
Автор

At 3:05 Nick shows code with a 'default!' value for the property. What does the '!' do?

PaulSinnema
Автор

I started using it just recently, thank for the video, this explains some of my questions!

rikk
Автор

One of most worthwhile channels to visit. Thank you so much.

salarkazazi
Автор

What does this default! exclamation mark mean? 3:03

TheChlastak
Автор

Hi, Nick! I wanna thank you for your videos, when I watch it then I learn English and .Net in the same time

artursabirov
Автор

Dammit man! You taught so much in 15 minutes. Especially learning of sharplab was amazing for me. Thanks for your work!

infinityminuszero
Автор

What the heck is that syntax for at 15:13 where it looks like "<FullName>k__BackingField" and also "<Clone>$()"
I'm just curious.
Also, I was kinda hoping you were also going to say that Records have the ability to be more effectively cleaned up by the GC. Because it seems like they are supposed to act as value types but with references. So if you create an instance of one in a function. It may be able to automatically free up the data when the function returns. So fewer allocations?

Andrewzero