Difference between Console.Read() and Console.Read

2019-01-03 06:34发布

I'm new to this field and I'm very confused: what is the real difference between Console.Read() and Console.ReadLine()?

11条回答
劫难
2楼-- · 2019-01-03 07:07

Console.Read() basically reads a character so if you are on a console and you press a key then the console will close, meanwhile Console.Readline() will read the whole string.

查看更多
三岁会撩人
3楼-- · 2019-01-03 07:17
Console.Read()

=> reads only one character from the standard input

Console.ReadLine()

=> reads all characters in the line from the standard input

查看更多
Animai°情兽
4楼-- · 2019-01-03 07:18

Console.Read() reads a single key, where Console.Readline() waits for the Enter key.

查看更多
5楼-- · 2019-01-03 07:19
  • ReadKey (returns a character): reads only one single character from the standard input stream. Usually used when you're giving options to the user in the console to select from, such as select A, B or C. Another prominent example, Press Y or n to continue.
  • ReadLine (returns a string): reads only single line from the standard input stream. As an example, it can be used to ask the user enter their name or age.
  • Read (returns an int): reads only one single character from the standard input stream. Similar to ReadKey except that it returns an integer.

This was clearly described with examples in the MSDN documentation (links are included above).

查看更多
做自己的国王
6楼-- · 2019-01-03 07:20

MSDN is actually pretty clear on this one.

  • Console.Read: Reads the next character from the standard input stream.
  • Console.ReadLine: Reads the next line of characters from the standard input stream.
查看更多
登录 后发表回答