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