Home >Backend Development >C#.Net Tutorial >Detailed explanation of the Console.Read() method in C#
Console.Read() method is used to read the next character from the standard input stream. This method basically prevents the user from returning when they type some input characters. It will terminate once the user presses ENTER.
Syntax:
public static int Read();
Return value: Returns the next character in the input stream, or a negative number (- if there is currently no character to read) 1).
Exception: This method will give an IOException if an I/O error occurs.
The following program illustrates the use of the above method:
Example 1:
// C# program to illustrate the use // of Console.Read Method using System; namespace GFG { class Program { static void Main(string[] args) { int x; Console.WriteLine("Enter your Character to get Decimal number"); // using the method x = Console.Read(); Console.WriteLine(x); } } }
Output:
Example 2:
// C# program to illustrate the use // of Console.Read Method using System; namespace GFG { class Program { static void Main(string[] args) { // Write to console window. int x; Console.WriteLine("Enter your Character to get Decimal number"); x = Console.Read(); Console.WriteLine(x); // Converting the decimal into character. Console.WriteLine(Convert.ToChar(x)); } } }
Output:
Related recommendations:《 C Tutorial》
This article is about the detailed explanation of the Console.Read() method in C#. I hope it will be helpful to friends in need!
The above is the detailed content of Detailed explanation of the Console.Read() method in C#. For more information, please follow other related articles on the PHP Chinese website!