• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

C#中的Console.Read()方法详解

c# 搞代码 4年前 (2022-01-09) 12次浏览 已收录 0个评论

Console.Read()方法用于从标准输入流中读取下一个字符。当用户键入一些输入字符时,此方法基本上阻止其返回。一旦用户按ENTER键,它就会终止。

语法:

public static int Read();

返回值:返回输入流中的下一个字符,如果当前没有要读取的字符,则返回负数(-1)。

例外:如果发生I / O错误,此方法将给出IOException。

以下程序说明了上述方法的使用:

本文来源gao($daima.com搞@代@#码8网^例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()方法详解的详细内容,更多请关注搞代码gaodaima其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:C#中的Console.Read()方法详解

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址