✅ How to automatically check for null?
I have following code:
existingItem
can be null so I will have NRE in this line var updatedItem = existingItem with
.
yes, we can solve this issue by checking existingItem
for null but I don't want to do this every time, code looks much better without any checks so how to avoid this?9 Replies
if it can be null, then you have to check for null
there's just no way around that
and what if it doesn't exist after all?
it is bad
how?
you have to handle it separately anyway
I know but.. it's a little bit annoying to do
Check for null, there is literally no good reason not to
How would you do this otherwise?
you could do
i guess
I want the null check to be done automatically or all errors to be logged automatically so that I don't have to do it all myself
but this looks good
there's no such thing as an "automatic null check"
you could call only
.First()
, but that will throw a different exception if the item doesn't existsigh.. okay, thanks for helping me