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 06:57

Console.Read() is used to read next charater from the standard input stream. When we want to read only the single character then use Console.Read().

Console.ReadLine() is used to read aline of characters from the standard input stream. when we want to read a line of characters use Console.ReadLine().

查看更多
做自己的国王
3楼-- · 2019-01-03 06:58

The basic difference is:

       int i = Console.Read();
        Console.WriteLine(i);

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..

      string s= Console.ReadLine();
      Console.WriteLine(s);

It gives the string as it is given in the input stream.

查看更多
叛逆
4楼-- · 2019-01-03 06:59

Difference between Read(),Readline() and ReadKey() in C#

Read()-Accept the string value and return the string value. Readline() -Accept the string and return Integer ReadKey() -Accept the character and return Character

Summary:

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

查看更多
Emotional °昔
5楼-- · 2019-01-03 07:02

Console.Read() reads only the next character from standard input, and Console.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.

查看更多
不美不萌又怎样
6楼-- · 2019-01-03 07:03

The difference of Read(),ReadLine() and Readkey() method are given below:

Read():This is static method in Console class:

   int i = Console.Read();//it always return int value.
   Console.WriteLine(i);

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():

  string s= Console.ReadLine();//it always return string value.
  Console.WriteLine(s);

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.

查看更多
神经病院院长
7楼-- · 2019-01-03 07:04

Console.Read() reads just a single character, while Console.ReadLine() reads all characters until the end of line.

查看更多
登录 后发表回答