📜  C#中的Console.Read()方法

📅  最后修改于: 2021-05-29 14:31:10             🧑  作者: Mango

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

下面的程序说明了上面讨论的方法的使用:

范例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));
    }
}
}

输出:

参考:

  • https://docs.microsoft.com/zh-cn/dotnet/api/system.console.read?view=netframework-4.7.2