I am using VS 2022 and its default version of c#. The following lines of code are being compiled succefully.
I was trying to find out what does =null!
mean. It seams that it is one of a new features of c# 10 that was not spoken about yet...
I am using VS 2022 and its default version of c#. The following lines of code are being compiled succefully.
I was trying to find out what does =null!
mean. It seams that it is one of a new features of c# 10 that was not spoken about yet...
If you enable Nullable Reference Types, the compiler will ensure that all non-nullable reference types are initialized after object creation. So they should be initialized either in constructor or in-place.
But for some classes, this is not useful, because they'll be initialized by reflection. This mainly relates to DTO or Entity Framework entities that are used in reflection-heavy frameworks.
So there exists a syntax to tell the compiler to "shut up, I know it's null, trust me". In this line you explicitly assign null to the field and tell the compiler to trust you.