C#中的Read()和ReadLine()方法有什么区别?
读()
Read()读取来自标准输入流的下一个字符。如果在控制台上按下某个键,则它将关闭。
int a = Console.Read() Console.WriteLine(a);
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...