Taking user input using Console.ReadLine()
Hello guys, can someone explain why my IDE (rider) has underlined the Console.ReadLine method pls.
What is wrong here? what can be corrected and why pls
11 Replies
The function returns null if stdin is closed
Unknown User•4d ago
Message Not Public
Sign In & Join Server To View
Console.ReadLine()!
Unknown User•4d ago
Message Not Public
Sign In & Join Server To View
yeah just test that
I thought, null was refering to like if we just press enter when we don't write anything
but in fact when we don't write anything, we just have an empty string
what does the ! do pls
Unknown User•4d ago
Message Not Public
Sign In & Join Server To View
using ! is like !important symbol in CSS
I think a better Console.ReadLine API would just throw an EndOfStream exception
Unknown User•4d ago
Message Not Public
Sign In & Join Server To View
by the way I just switch from string to var, it seems the keyword was no longer underlined, is that a reason for that?
Also, when should we use the var keyword? each time we declare a variable that we know we would be assigning something to it?
ah the thing is
when we use var, we are telling the compiler that we will always expect something to be entered?
it works just like the ! thing I think
You have the option to write down the type, or to type
var
and let the compiler pick the type based on the what the function returns
Some people have different tastes, but the majority of people use var
whenever possible