Converting null literal or possible null value to non-nullable type.
Hey all real quick question, am still trying to learn c# and am getting a warning when using Console.ReadLine(), if anyone could explain real quick i would greatly appreciate it, thanks!
17 Replies
No idea, honestly. It seems perfectly fine to me
see the weird part is that without the ?? "Test", the whole
Console.ReadLine()
has a warning
but with it, only the console part has a warningYes, because it returns a
string?
not a string
yes i understand that
And it really doesn't make sense for just the
Console
to be highlightedexactly
Try restarting (I assume) VS Code?
i have and the warning remains
Weird
so its definitely a vscode issue, becuase i input the same code into visual studio and no warning
VSCode has always been subpar C# experience
Some say VSCode is great .. they are lying
Mostly because the plugins are god awful and breaks constantly
not for C# at least
but Rust from what I've heard works best there
It does, yes.
Sadly RustRover is way too unstable and demanding.
Do you get the warning when you run
dotnet build
It would be great if you could not make things updoesnt when you put nothing in the console it just an empty string?
Documentation to the rescue! https://learn.microsoft.com/en-us/dotnet/api/system.console.readline?view=net-8.0#remarks
If the Ctrl+Z key combination (followed by Enter on Windows) is pressed when the method is reading input from the console, the method returns null. This enables the user to prevent further keyboard input when the ReadLine method is called in a loopIf the input stream is closed, then
Console.ReadLine
returns nullah i see
the idk why this script doesnt work
this seems weird did you fix it yet?
or maybe try using a "string?" instead of a normal string