❔ Appease "Property is uninitialized" without setting a default value? Possibly make it required?
Hello, I am trying to go through my code and fix all the warnings to improve code quality. I have this string property that must be set when this class is instantiated. It does not have a default value because it must be set every time when you create an instance of this class. Because of this I get this warning. Is there an annotation or something to tell the compiler "this property is required, and so this class cannot be instantiated without it" to appease the warning?
12 Replies
Make the property
required
If you can't do that because you're using an old compiler version, you can do
= null!;
to shut the compiler uprequired is not shutting it up but im on the latest version of rider
ill try the = null solution
technically worked but now its upset its redundant lol
ill just make it an empty string by default even tho its required i guess
Not the attribute
.NET 7 feature mmaybe?
Yeah
If you're using old versions of .NET,
= null!;
or = default!;
is about as good as you can dothe best way is to ignore these warnings by putting a pragma over your code
Rider has a fix for that
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.