Safe to ignore non-null value on exit contructor? (disabling warning)
Can I safely add this as a ignore?
I don't really know how I would fix this otherwise
5 Replies
You can write
= null!;
after the { get; set; }
and that will force the compiler to shut up.
And yes for EF you can safely ignore it as EF will set that property before you can access it, but the compiler can't know that.im guessing adding a prabma is also fine?
yep
You could also do
#nullable disable
at the top of the fileAnd when C# 11 arrives,
required
properties will be the solution to this issueIm already using it :)
Forces me to initialize that property when i construct the type