C
C#7mo 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
Angius7mo ago
No idea, honestly. It seems perfectly fine to me
Mathall
MathallOP7mo 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
Angius7mo ago
Yes, because it returns a string? not a string
Mathall
MathallOP7mo ago
yes i understand that
Angius
Angius7mo ago
And it really doesn't make sense for just the Console to be highlighted
Mathall
MathallOP7mo ago
exactly
Angius
Angius7mo ago
Try restarting (I assume) VS Code?
Mathall
MathallOP7mo ago
i have and the warning remains
Angius
Angius7mo ago
Weird
Mathall
MathallOP7mo ago
so its definitely a vscode issue, becuase i input the same code into visual studio and no warning
Buddy
Buddy7mo 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
Petris7mo ago
not for C# at least but Rust from what I've heard works best there
Buddy
Buddy7mo ago
It does, yes. Sadly RustRover is way too unstable and demanding.
333fred
333fred6mo ago
Do you get the warning when you run dotnet build It would be great if you could not make things up
sashimiman
sashimiman6mo ago
doesnt when you put nothing in the console it just an empty string?
canton7
canton76mo 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
sashimiman6mo 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