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()方法详解的详细内容。