❔ Non-nullable property must contain a non-null value when exiting constructor
I know what it says and what it wants my to do. However, my situation is: I have a bunch of objects (as properties) and that not all of them needs instantiating in a main class constructor. Given a condition, some will be and some won't be.
In case of one that won't be, I still have no idea how to make the warning go away.
Any suggestion? I'm sure how to Google this since using the warning would send me to a non-desirable direction.
7 Replies
If some properties might not be set, then make them nullable
@🌈 Thinker 🌈 I did, however the Console still warns me about null
Can you show your code?
Mind providing code snippet?
Here's the code. I'm doing an exercise, if player chooses "small", there won't be maelstroms in the game
So the console tells me, Maelstrom must not be null when existing in the constructor.
You need ? after the [], not before
the way its written by you is an non-nullable array of nullables
you need nullable array though
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.