What is the difference between Read() and ReadLine() methods in C#?


Read()

The Read() reads the next characters from the standard input stream. If a key is pressed on the console, then it would close.

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

ReadLine()

It reads the next line of characters from the standard input stream.

Example

 Live Demo

using System;
class Program {
   static void Main() {

      int x = 10;
      Console.WriteLine(x);
      Console.Write("
Press any key to continue... ");       Console.ReadLine();    } }

Output

10
Press any key to continue...

Updated on: 22-Jun-2020

466 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements