Check out my courses: https://nickchapsas.com
Become a Patreon and get source code access: https://www.patreon.com/nickchapsas
Hello everybody I’m Nick and in this video I will show you how Properties evolved in C# from the very first version until the latest C# 10 version. I will explain why they were added and what problem they were solving and take a look at how they changed throughout the years.
Timestamps
Intro – 0:00
Why do properties exist? – 0:54
C# 1 – 2:48
C# 3 – 6:23
C# 6 – 9:19
C# 7 – 11:02
C# 8 – 12:33
C# 9 – 14:06
C# 10 – 16:19
C# 9’s records – 16:49
Don’t forget to comment, like and subscribe 🙂
Social Media:
Follow me on GitHub: http://bit.ly/ChapsasGitHub
Follow me on Twitter: http://bit.ly/ChapsasTwitter
Connect on LinkedIn: http://bit.ly/ChapsasLinkedIn
Keep coding merch: https://keepcoding.shop
#csharp #dotnet
Hi Nick, I tried this approach to create readonly properties but .Net5 DI doesn't pass anything to them. In example: public IContactsProcessService _сontactProcessService { get; init; }. Is there way throw long Ctor's and use this smart properties?
P.S. The "property init" is a syntax sugar only for design time. We can set value using reflection, normally.
Evolution of dynamic type
Great summary, but since you mentioned record you should also mention record structs.
You forgot to show how the init properties appear in IL 😉
And the implications.
Awesome work Nick
Properties are the greatest invention in programming language history
* cough cough * Java
Missed an analysis why these shorthands should be in language rather than some IDE macros that generate the boilerplate code. Is it really a good language principle to have as much syntax (and syntax variants) as possible to further some concept of terseness as ultimate goal? It is often implied that terseness saves time coding (but if it goes at the expense of readability and language orthogonality that is doubtful), but often many of the same goals can be achieved with some easily triggered autocompletion options in the IDE
I want a feature of auto-generated field being accessible in getter or setter without declaring it.
Thank you, it's a good idea to make such videos, I left this language a long time ago and when I came back to it I found a lot of changes and new features which I'm not familiar with.
a field:Obsolete attribute for the backing field… why would you even do that? What purpose does this serve?
How would you even use it since the compiler won't let you use the autogenerated backing field directly
I think Pattern Matching sintax introduced on C#8 is a good option when you are comparing multiple values for the same property. At least it gives you different flavors to play around.
So depending on the number of properties and nesting levels, you can have cleaner if statements.
foreach (var user in users)
{
if (user.Birthday is { Year: 2022, Month: 03 })
{
Console.WriteLine(user.Name);
}
if (user is { Birthday: { Year: 2022, Month: 03 } })
{
Console.WriteLine(user.Name);
}
if (user is { Birthday.Year:2022, Birthday.Month: 03})
{
Console.WriteLine(user.Name);
}
}
Just writing some VBA in Excel. To be easy I just declare PUBLIC vars (no PROPERTY). Why use Properties (when get/set is public) ?
You gotta love these videos…nice work as always!
Very nice and instructive this historical perspectives…
showing how and why something evolved…
please do more of this,,,
and I also would like to hear your opinion on what would be the next step in the topics evolution…
or how it should evolve…
Thanks for the video. I didn't know about the "is" and "not" key words. From now on, I'll use them more often, because I find them easier to read than != for example.
I love your videos, learning a lot about C#, but sadly at every video I say to myself about C# …so messy! Crazy considering the C# creator knows better from his previous language, Delphi.
These came from Delphi. The creator of Delphi, created c#
Readonly properties? With readonly keyword
I was hoping when C# 10 came up, you'd start with semi-auto-properties. But, after re-googling it, it seems this has been stashed for C# 11… Unfortunately.
Nice, an evolution of Lists video would be cool, too. Seeing how Generics come in 2.0 and late different initializers, etc.
You are doing an icredible work 😀 I am really imprest. Greating from POLAND 🙂
Congratulations with 100K subscribers! Totally deserved it! Next target – 1M
Good stuff mate! Keep em coming 🙂
hey Nick, what do you think about a new course for c# source generators?
No ha muerto C# aún?. Fuaa.
The one thing C# hasn't assimilated is OTBS. They incorporate everything else that's good; it's time guys. Make the switch.