I'm new to this field and I'm very confused: what is the real difference between Console.Read()
and Console.ReadLine()
?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
Console.Read()
is used to read next charater from the standard input stream. When we want to read only the single character then useConsole.Read()
.Console.ReadLine()
is used to read aline of characters from the standard input stream. when we want to read a line of characters useConsole.ReadLine()
.The basic difference is:
paste above code and give input 'c', and the output will be 99. That is Console.Read give int value but that value will be the ASCII value of that..
On the other side..
It gives the string as it is given in the input stream.
Difference between Read(),Readline() and ReadKey() in C#
Read()
-Accept the string value and return the string value.Readline()
-Accept the string and return IntegerReadKey()
-Accept the character and return CharacterSummary:
1.The above mentioned three methods are mainly used in Console application and these are used for return the different values . 2.If we use Read line or Read() we need press Enter button to come back to code. 3.If we using Read key() we can press any key to come back code in application
Console.Read()
reads only the next character from standard input, andConsole.ReadLine()
reads the next line of characters from the standard input stream.Standard input in case of Console Application is input from the user typed words in console UI of your application. Try to create it by Visual studio, and see by yourself.
The difference of Read(),ReadLine() and Readkey() method are given below:
Read():This is static method in Console class:
paste above code and give input '1', and the output will be 49. That is Console.Read give int value but that value will be the ASCII value of that.. ReadLine():
It gives the string as it is given in the input stream.
ReadKey(): this method is used to hold the output screen.when any key is press. Read() and ReadLine() is used the enter key for exit.
Console.Read()
reads just a single character, whileConsole.ReadLine()
reads all characters until the end of line.