console.read()方法用于从标准输入流中读取下一个字符。当用户键入一些输入字符时,此方法基本上阻止其返回。一旦用户按enter键,它就会终止。
语法:
public static int Read();
返回值:返回输入流中的下一个字符,如果当前没有要读取的字符,则返回负数(-1)。
例外:如果发生I / O错误,此方法将给出IOException。
以下程序说明了上述方法的使用:
示例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); } } }
输出:
示例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)); } } }
输出:
相关推荐:《C教程》
本篇文章就是关于C#中的Console.Read()方法详解,希望对需要的朋友有所帮助!
以上就是C#中的Console.Read()方法详解的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号