C
C#5mo ago
Mathall

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!
No description
17 Replies
Angius
Angius5mo ago
No idea, honestly. It seems perfectly fine to me
Mathall
MathallOP5mo ago
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 warning
Angius
Angius5mo ago
Yes, because it returns a string? not a string
Mathall
MathallOP5mo ago
yes i understand that
Angius
Angius5mo ago
And it really doesn't make sense for just the Console to be highlighted
Mathall
MathallOP5mo ago
exactly
Angius
Angius5mo ago
Try restarting (I assume) VS Code?
Mathall
MathallOP5mo ago
i have and the warning remains
Angius
Angius5mo ago
Weird
Mathall
MathallOP5mo ago
so its definitely a vscode issue, becuase i input the same code into visual studio and no warning
Buddy
Buddy5mo ago
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
Petris
Petris5mo ago
not for C# at least but Rust from what I've heard works best there
Buddy
Buddy5mo ago
It does, yes. Sadly RustRover is way too unstable and demanding.
333fred
333fred5mo ago
Do you get the warning when you run dotnet build It would be great if you could not make things up
sashimiman
sashimiman5mo ago
doesnt when you put nothing in the console it just an empty string?
canton7
canton75mo ago
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 loop
If the input stream is closed, then Console.ReadLine returns null
sashimiman
sashimiman5mo ago
ah 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
Want results from more Discord servers?
Add your server