Тёмный

Primary Constructors in C# 12 - WORTH IT? 

Claudio Bernasconi
Подписаться 17 тыс.
Просмотров 1,8 тыс.
50% 1

Today, we want to learn about one of the new C# 12 features coming with .NET 8 in November 2023. We will learn what Primary Constructors are, how to define them, and when to use them.
00:00 Introduction
00:16 Primary Constructors in Action
02:24 Secondary Constructors
02:57 ASP.NET Core WebAPI - Dependency Injection Example
03:49 Primary Constructors Generatees Mutable Fields
04:22 Immutable Fields (readonly)
05:25 Comparison with Record Types
06:38 When to Use Primary Constructors?
07:35 Conclusion
🔥 C#/.NET Bootcamp: The Fundamentals & more (Code FRIENDS10 for 10% OFF)*
claudiobernasconi.ch/dotnet-c...
📌 .NET Developer Roadmap
claudiobernasconi.ch/learn-do...
📌 RU-vid Playlists:
The FREE Blazor Crash Course: • The FREE Blazor Crash ...
Blazor: • Blazor
✅ SUBSCRIBE FOR MORE VIDEOS
Subscribe: 🔔 claudiobernasconi.ch/Subscribe
🚀 CONNECT & SUPPORT
Twitter: / chbernasconic
Blog: claudiobernasconi.ch
Newsletter: claudiobernasconi.ch/newsletter
* Affiliate Link: I earn a small commission at no additional cost

Наука

Опубликовано:

 

15 июл 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 13   
@ClaudioBernasconi
@ClaudioBernasconi 9 месяцев назад
What do you think of primary constructors in C# 12? Will you use them? 🤔
@vivekkaushik9508
@vivekkaushik9508 9 месяцев назад
I love this feature. This feature will make our services more leaner as all those dependencies won't be needed to be assigned to backing fields.
@ClaudioBernasconi
@ClaudioBernasconi 9 месяцев назад
Yes, it makes it a lot leaner, I agree. Do you worry about newcomers having a hard time learning about primary constructors or do you believe it will be a standard feature in a few years?
@10Totti
@10Totti 9 месяцев назад
@@ClaudioBernasconiStandard.
@programedegraca
@programedegraca 9 месяцев назад
Que conteúdo excelente. Muito obrigado.
@ClaudioBernasconi
@ClaudioBernasconi 8 месяцев назад
Muito obrigado.
@dustinjoosen5901
@dustinjoosen5901 8 месяцев назад
I really like them. I'm sure there'll be some good use-cases. I'll see when it comes up
@ClaudioBernasconi
@ClaudioBernasconi 8 месяцев назад
Definitely an interesting feature. We'll see how it shapes the C# codebases in the future. 😉
@pilotboba
@pilotboba 9 месяцев назад
This is an old feature that I thought was in C# several versions ago. Apparently they dropped it. They then used it for Records and now are adding it for a normal class. As far as you having to understand it, I think that's true of most C#. :) But yes it is less obvious what is going on here, what is in scope, the fact that they are mutalbe, etc. The same can be said about pattern matching and switch expressions. That said, you should 100% use file-scoped name spaces, unlike what you showed here. I think that one is a no-brainer.
@ClaudioBernasconi
@ClaudioBernasconi 9 месяцев назад
I use file-scoped namespaces for my projects, but when I show a new language feature I prefer having everything else on default. Thanks for leaving your comment. 👍
@KennethSiewersMller
@KennethSiewersMller 6 месяцев назад
They are not fields, they are global scoped parameters. There's a big difference, since parameters cannot be declared as readonly.
@ClaudioBernasconi
@ClaudioBernasconi 6 месяцев назад
Thanks for your comment. Can you elaborate on your statement? I have never heard of global scoped parameters. All I know is that the following looks pretty much like a private field. ibb.co/sjTDB5m
@KennethSiewersMller
@KennethSiewersMller 6 месяцев назад
@@ClaudioBernasconi look at the tip when you hover the name. It says “parameter”. Yes, it looks like a field, but it’s a parameter. You’ve never heard of it because it’s new in C# 12 😉 But don’t think of it as a field, although it looks like it 🙂
Далее
Primary Constructors in C# 12 Explained!
9:39
Просмотров 23 тыс.
меня не было 9 дней
12:48
Просмотров 1,9 млн
What's New in C# 12 | .NET Conf 2023
35:28
Просмотров 55 тыс.
Don't throw exceptions in C#. Do this instead
18:13
Просмотров 253 тыс.
Dependency Injection, The Best Pattern
13:16
Просмотров 765 тыс.
C# Has New Primary Constructors
2:52
Просмотров 364
.NET 8 | Everything you NEED to KNOW!
9:04
Просмотров 25 тыс.
КРУТОЙ ТЕЛЕФОН
0:16
Просмотров 5 млн