✅ C sharp help static void
Hello everyone I am new to C sharp and I was wondering if someone can help me with my code it says theres an error but I dont know how to fix the error can somone please help me
7 Replies
Console.ReadLine()
returns a string?
so a string
value that can also be null
In an event where it is null
, you can't .ToLower()
it
The most proper way to deal with it would be using a null-coalescing operator, for example
So I should replace line 35 with
var text = Console.ReadLine()?.ToLower() ?? "";
A simpler but less idiomatic way would be the null-forgiving operator that basically says "trust me bro, this is not
null
". But if it does happen to be null
, well, you're out of luck and your app breaks:
YesOkay tysm
Well, in your case the variable is not named
text
but guess
But, yeahThank you so much for the help
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.