C# Readline Method - Console.ReadLine() Method in C#
C# Readline Method
- In C# Console.Writeline () is a method used to print the entire statement of a single line and transfer control to the next line of the console.
- Equally to the Console.WriteLine(), the Read Line () method is used to read the entire line of string or statement value from the user until the Enter key is pressed to transfer control to the next line.
Console.ReadLine() Method
- In C#, Console. ReadiLine () method is a commonly used method or function to take an input from the user until the enter key is pressed.
- It is a method that reads each line of string or values from a standard input stream.
- In C#, it is a predefined method of the Console class (System Namespace).
- This method reads and only returns the string from the stream output device (console) until a newline character is found.
- When we want to read a character or numeric value from the user, we need to convert the string to the appropriate data sets.
Syntax
public static string ReadLine ();
Sample Code
Output
Example
- Write a program to print the user's first and last name using the Read Line () function in C#.
Sample Code
Output
Read () Method
- In C#, Read () method is used to read a single character from the user and it is different from the Read Line () method because the read Line () method receives each line input from the user until the line is finished and control transfer to the next statement to read strings.
Output
Read Key ()
- In C# Read Key () method is used to get the next character, or the user presses any key to exit the program.
- It holds the screen until the user presses any key from the keyboard and pressed key will be displayed on the console.