首页后端开发ASP.NETC#中的Console.Read()方法详解

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

时间2024-01-31 03:59:03发布访客分类ASP.NET浏览464
导读:收集整理的这篇文章主要介绍了C#中的Console.Read( 方法详解,觉得挺不错的,现在分享给大家,也给大家做个参考。Console.Read( 方法用于从标准输入流中读取下一个字符。当用户键入一些输入字符时,此方法基本上阻止其返回。一...
收集整理的这篇文章主要介绍了C#中的Console.Read()方法详解,觉得挺不错的,现在分享给大家,也给大家做个参考。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()方法详解的详细内容,更多请关注其它相关文章!

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!

C#

若转载请注明出处: C#中的Console.Read()方法详解
本文地址: https://pptw.com/jishu/593451.html
C中scanf()和gets()之间的区别(代码示例) 一文深入了解 Node 中的事件循环

游客 回复需填写必要信息