Coding Shorts: For The Record - Why You Should Use (Records in C#)

  Рет қаралды 11,233

Shawn Wildermuth

Shawn Wildermuth

Күн бұрын

Records are here for C#! Are you confused by why they exist? I was too. Let's look at it:
00:00 - Introduction
00:28 - Getting Started
03:03 - Using Records
04:30 - Simplified Syntax
05:35 - Immutability
08:33 - Inheritance in Records
10:05 - Wrapping Up
Source Code: github.com/shawnwildermuth/co...
If you like this video, you might like other videos in my Instructional Videos:
- • Instructional Videos
You can hire me too! You can reach me at my new website:
- shawn.wildermuth.com

Пікірлер: 58
@TheAndronKolaider
@TheAndronKolaider 29 күн бұрын
The best explanation you can ask for
@swildermuth
@swildermuth 29 күн бұрын
Thanks. I am glad it helped.
@raphaellukas3328
@raphaellukas3328 10 ай бұрын
When I was looking for a video to explain the C# record, I knew I was in good hands. Always to the point, no big talk around it. Many greetings from Germany
@swildermuth
@swildermuth 10 ай бұрын
Glad you liked it!
@henrikchristensen65688
@henrikchristensen65688 11 ай бұрын
I love your short but very informative videos! You just got a new subscriber!
@samwalter17
@samwalter17 Ай бұрын
Brilliant video, that was so concise and informative, thank you.
@swildermuth
@swildermuth Ай бұрын
Glad it was clear!
@NoonKnite
@NoonKnite Жыл бұрын
great explanation! i've struggled with how classes and recs are different, so this really helped a lot.
@AlexapolloRodopoulos
@AlexapolloRodopoulos Ай бұрын
Amazing explanation and demonstration keep it up!
@swildermuth
@swildermuth Ай бұрын
Thanks, will do!
@jasondelauro
@jasondelauro 2 ай бұрын
You have an excellent concise teaching style.
@DmitriyBelous
@DmitriyBelous Жыл бұрын
Great explanation, thanks!
@timothyvandyke9511
@timothyvandyke9511 Жыл бұрын
I would absolutely love if this encourages people to put a bunch of (related) types into the same file so we don't get a bajilllion files just for simple types.
@godfathermikal
@godfathermikal Жыл бұрын
Sweet. That makes sense. Didn't really see how record was useful, but this makes sense. Thanks!
@swildermuth
@swildermuth Жыл бұрын
No problem!
@tytz100
@tytz100 8 ай бұрын
this was the clearest explanation video I've ever seen in a while. GJ!
@swildermuth
@swildermuth 8 ай бұрын
Glad it helped!
@pukey3226
@pukey3226 7 ай бұрын
Thanks Shawn
@swildermuth
@swildermuth 7 ай бұрын
yw
@jemakrol
@jemakrol 4 ай бұрын
First time visitor. Senior dev that just wanted to see some different explanations on the topic in the context on how to best describe it. You explain in a concise and pedagogical way. You do this without all the the Bells and Whistles that usually comes with KZfaq videos. I hesitate to search for explanations in video format because it often comes with too much distraction and ambition. Motivated or not, things I didn't want. This, however, really gets to the point in a straight forward and relaxing manner. Nice!
@D3VW1Z4RD
@D3VW1Z4RD 8 ай бұрын
Good video, and ur voice is so relaxing sir.
@swildermuth
@swildermuth 8 ай бұрын
Thank you kindly!
@matadorso
@matadorso Жыл бұрын
Cool video 👌
@user-jq6uh5vu2l
@user-jq6uh5vu2l Жыл бұрын
Thanks this was great.
@swildermuth
@swildermuth Жыл бұрын
Glad you enjoyed it!
@JohnSmith-op7ls
@JohnSmith-op7ls 3 ай бұрын
You should mention how and when a record will be allocated to the heap vs stack as this is important for performance and GC. Also, go into when and how copying of a record instance is a fill/deep copy, meaning no references are reused, and when it is a shallow copy, meaning value types are copied but reference types only have the pointer copied.
@stxnw
@stxnw 2 ай бұрын
this is standard knowledge so there’s no need to re-explain this.
@officemishler3364
@officemishler3364 Жыл бұрын
Video and audio quality are ridiculously good. Need S Dubs in the highest def possible
@swildermuth
@swildermuth Жыл бұрын
S Dubs?
@officemishler3364
@officemishler3364 Жыл бұрын
@@swildermuth Your initials
@LOL-cp6js
@LOL-cp6js 6 ай бұрын
helpful👍🔥
@swildermuth
@swildermuth 6 ай бұрын
Glad to hear that
@zaharivaklinov
@zaharivaklinov Жыл бұрын
Thanks for this! But what's your take on creating DTOs with records instead of with classes?
@jonathansaindon788
@jonathansaindon788 10 ай бұрын
This is probably a good fit, but to me the best use case for records is multithreading. Since you can’t edit them after the fact, it forces you to use them in a thread-safe manner.
@Elilmu_Nur
@Elilmu_Nur 2 ай бұрын
You didn't really say why we should use records but thanks anyway.
@peterstangelo8627
@peterstangelo8627 Жыл бұрын
Thanks for doing these insighful coding shorts. I noticed you use a shortcut to run the 'dotnet.exe' -was it a case of just making a copy and naming it 'n.exe' (in the same folder)?
@swildermuth
@swildermuth Жыл бұрын
I got it from here: github.com/faniereynders/dotnet-sdk-helpers I renamed their dot.cmd to n.cmd
@peterstangelo8627
@peterstangelo8627 Жыл бұрын
@@swildermuth thank you
@williamliu8985
@williamliu8985 11 ай бұрын
Hi Shawn, could you give a video talking about the "readonly record struct"? The name seems a bit wired, and it is rarely mentioned. What is its application scenario?
@fifty-plus
@fifty-plus 4 ай бұрын
It's well documented on the Microsoft Learn site.
@rogerstich7603
@rogerstich7603 5 ай бұрын
First of all, even if i point out a flaw, i really love your shorts, this video helped me alot in finding a simple way to explain this construct to my trainees and junior devs. The flaw im talking about starts at 1:50 of your video. There you are telling that you make a copy of the product by writing this: var product2 = product; But thats not true, you dont make a copy you just assign the pointer to another variable, you copied the pointer, not the object. You can test it by using this Code: var product2 = product; product.Description = "Description of Product"; Console.WriteLine($"Product1: {product.Description}"); Console.WriteLine($"Product2: {product2.Description}"); If i had a Copy, then only the first Console WriteLine should contain the Description string "Description of Product". But both does and thats because those variables actually do point to the same object and for that makes your explaination later with equals a bit weird.
@swildermuth
@swildermuth 5 ай бұрын
I didn't mean to imply that. My bad.
@rogerstich7603
@rogerstich7603 5 ай бұрын
@@swildermuththanks for the response
@49riddickful
@49riddickful Жыл бұрын
How is that last bool method you wrote a part of the record above? What indicates that?
@swildermuth
@swildermuth Жыл бұрын
It is just like a class declaration, you can add members (in this case a method) in the body of the record. I think that's what you're asking.
@jameshancock
@jameshancock Жыл бұрын
What I really want to do is make all of my DTOs readonly record struct. But it doesn't work in a number of cases including [AsParameter].
@swildermuth
@swildermuth Жыл бұрын
Not sure why that would be. Can you explain? I'm curious. Difference between struct and record is inheritance (though likely not that useful but good to know).
@jameshancock
@jameshancock Жыл бұрын
@@swildermuth One is on the heap the other isn't. Correct usage of structs instead of classes in high volume systems minimizes garbage collection. It's unfortunate that you can't inherit or at least say "implement identical properties" of a struct, but when using protobuf of messagepack or even graphql which generate DTOs from other formats, that doesn't really matter, and the perf improvement is pretty nuts.
@henrik3098
@henrik3098 7 ай бұрын
thanks my amercian bro
@swildermuth
@swildermuth 6 ай бұрын
You're welcome
@robadobdob
@robadobdob 13 күн бұрын
You can also mutate the record back onto itself e.g. product = product with { Price = 1.99m } I use this in Fluxor where the current state is passed into a reducer method.
@swildermuth
@swildermuth 12 күн бұрын
Technically true, but it is new copy (a new reference). Right?
@robadobdob
@robadobdob 12 күн бұрын
@@swildermuth yeah correct, it creates a new copy and assigns it back to the variable.
@ashimov1970
@ashimov1970 11 ай бұрын
how do I convert records into classes and vice versa?
@ghevisartor6005
@ghevisartor6005 6 ай бұрын
i use chatgpt
@ashimov1970
@ashimov1970 6 ай бұрын
@@ghevisartor6005 😆👍
@Ben-nc9qw
@Ben-nc9qw 3 күн бұрын
Are you the voice of Lester in GTA5?
@swildermuth
@swildermuth 3 күн бұрын
I wish!
Coding Shorts: Required Viewing About Required Members
5:28
Shawn Wildermuth
Рет қаралды 1,5 М.
Surprise Gifts #couplegoals
00:21
Jay & Sharon
Рет қаралды 32 МЛН
Glow Stick Secret 😱 #shorts
00:37
Mr DegrEE
Рет қаралды 128 МЛН
[Vowel]물고기는 물에서 살아야 해🐟🤣Fish have to live in the water #funny
00:53
Coding Shorts: Using Azure Entra ID to Protect Your APIs
19:22
Shawn Wildermuth
Рет қаралды 1,7 М.
Why is C# Evolving This Way?
15:02
Zoran Horvat
Рет қаралды 19 М.
Every feature added in C# 10 with examples
15:59
Nick Chapsas
Рет қаралды 124 М.
Where are types allocated in .NET and why people get it so wrong
14:35
Coding Shorts: C# Type Inference or, How I Learned to Love 'var'
15:19
Shawn Wildermuth
Рет қаралды 1,1 М.
Coding Shorts: Tuples in C#
6:23
Shawn Wildermuth
Рет қаралды 6 М.
Primary Constructors in C# 12 Explained!
9:39
James Montemagno
Рет қаралды 23 М.
C# Records are Functional - Try Them Out That Way!
13:13
Zoran Horvat
Рет қаралды 3,7 М.
C# Tutorial. Records - What They are and How to Use Them
16:10
Nick Proud
Рет қаралды 1,7 М.
Индуктивность и дроссель.
1:00
Hi Dev! – Электроника
Рет қаралды 984 М.
Best Gun Stock for VR gaming. #vr #vrgaming  #glistco
0:15
Glistco
Рет қаралды 5 МЛН
Радиоприемник из фольги, стаканчика и светодиода с батарейкой?
1:00
😱НОУТБУК СОСЕДКИ😱
0:30
OMG DEN
Рет қаралды 339 М.
НЕ ПОКУПАЙ iPad Pro
13:46
itpedia
Рет қаралды 289 М.