C#中的Read(),ReadKey()和ReadLine()方法有什么区别?
读()
Read()从标准输入流中读取下一个字符。如果在控制台上按下某个键,则它将关闭。
int az = Console.Read() Console.WriteLine(z);
ReadKey()
它仅从标准输入流中读取单个字符。
ReadLine()
从标准输入流中读取下一行字符。
示例
using System;
class Program {
static void Main() {
int x = 10;
Console.WriteLine(x);
Console.Write("\nPress any key to continue... ");
Console.ReadLine();
}
}输出结果
10 Press any key to continue...