❔ Non-nullable field 'rating' must contain a non-null value when exiting constructor
Why am i getting this warning:
Non-nullable field 'rating' must contain a non-null value when exiting constructor
?
Before exiting the constructor Rating = aRating
is executed and thus rating should be set rating
to "G"
or "PG"
right?
![](https://utfs.io/f/62af5daf-88e2-4010-bb1e-4d519d5a1b89-1nq2cb.png)
4 Replies
It can't see that setting
Rating
always sets rating
under the hood
You can add [MemberNotNull(nameof(rating))]
to the setter to make the compiler happy
(I also wrote a switch with pattern matching instead of the if statement, you can use your original setter body if you don't understand or don't like how that looks)Thank you!
I haven't seen this way of writing a switch statement but it looks very concise. TY! 🙂
![heartowo](https://cdn.discordapp.com/emojis/626464756156596244.png)
its a "switch expression". They are very very nice.
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.