This method is used to read the next line of characters from the standard input stream. It comes under the Console class(System Namespace). If the standard input device is the keyboard, the ReadLine method blocks until the user presses the Enter key. And if standard input is redirected to a file, then this method reads a line of text from a file.
Syntax: public static string ReadLine ();
Return Value: It returns the next line of characters of string type from the input stream, or null if no more lines are available.
- IOException: If an I/O error occurred.
- OutOfMemoryException: If there is insufficient memory to allocate a buffer for the returned string.
- ArgumentOutOfRangeException: If the number of characters in the next line of characters is greater than MaxValue.
Below program illustrate the use of the above-discussed method:
Example 1: Here, take input from the user. Since age is an integer, we typecasted it using Convert.ToInt32() Method. It reads the next line from the input stream. It blocks until Enter key is pressed. Hence it is commonly used to pause the console so that the user can check the output.
Example 2: To pause the console
Explanation: In the above output you can see that the console is paused. The cursor will blink continuously until you press Enter key.
- Difference between Method Overriding and Method Hiding in C#
- C# | Uri.ToString() Method
- Extension Method in C#
- C# | Uri.IsWellFormedOriginalString() Method
- jQuery | get() Method
- C# | CompareOrdinal() Method
- jQuery | before() Method
- Stack.Pop() Method in C#
- C# | IsNullOrEmpty() Method
- C# | Uri.IsHexDigit() Method
- Stack.Contains() Method in C#
- C# | Random.Next() Method
- C# | Uri.IsBaseOf(Uri) Method
- C# | Uri.FromHex() Method
- C# | ToLower() Method
- C# | StartsWith() Method
- Queue.Contains() Method in C#
- C# | ToUpper() Method
- C# | Copy() Method
- C# | Uri.GetHashCode() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.