Primary constructors in C# sees params added to a class

Опубликовано: 13 Октябрь 2024
на канале: Round The Code
2,417
68

Primary constructors are one of the new C# 12 features.

It allows you to add parameters to a class and therefore override the default behaviour of initialising a class.

The aim of this feature is to reduce code bloat and can also be used with dependency injection.

We'll show you how to add primary constructors to a class, what happens when you add a constructor alongside primary constructors, and how it can be used with dependency injection.

📖 Learn .NET and C# with our online courses 📖
https://www.roundthecode.com/dotnet-c...

👨‍💻Take our .NET and C# coding challenges👨‍💻
https://www.roundthecode.com/dotnet-c...

► More information:
https://www.roundthecode.com/dotnet-t...

🎥 Playlist 🎥
   • .NET 8 and C# 12 new features  

► Chapters
0:00 What are primary constructors?
0:25 Coding challenges
0:35 Current default constructor
0:54 Parameter constructor
1:41 Define primary constructor
2:44 Primary constructors in dependency injection
3:09 Reminder of primary constructors
3:19 Review of primary constructors

#csharp #csharpprogramming #csharpdotnet