❔ Reading from stdin
So, I'm trying to work with basic IO stuff. I have this snippet:
I get a warning about assigning a nullable value to a non-nullable variable. I understand what the warning is saying, but I'm not sure how I'm supposed to do any better than this considering I am already checking for null values. Any recommendations?
7 Replies
Console.ReadLine()
will almost never return null, i think the only situation is if the user hits ctrl+zYup, so you can silence that warning with a bang
it's one of those things where it's probably okay to just suppress the warning like
Console.ReadLine()!
Noted, thank you both
Alternatively,
to get an empty string instead of
null
alternatively,
string? line;
does not require any other code changesWas 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.