❔ 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?
![](https://utfs.io/f/e20f2620-e655-420e-a7a0-b4389b98297b-1nq2cb.png)
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
![](https://utfs.io/f/5e77b725-7c09-49b0-ba86-57cc324a4b5a-1nq2cb.png)
ill try the = null solution
technically worked but now its upset its redundant lol
![](https://utfs.io/f/ed5890fc-a673-45cf-8abf-f8186f71d783-1nq2cb.png)
ill just make it an empty string by default even tho its required i guess
Not the attribute
![](https://utfs.io/f/b6dfb1dc-94e5-4ee3-ac62-a5232cd92b66-1nq2cb.png)
.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.