C#中的Console.ReadLine()方法

Console.ReadLine() Method in C#

C#中的Console.ReadLine()方法用于从标准输入流中读取下一行字符。

句法

语法如下-

1
public static string ReadLine ();

现在让我们看一个示例,以在C#中实现Console.ReadLine()方法-

<!-

现场演示

->

1
2
3
4
5
6
7
8
9
using System;
public class Demo{
 public static void Main(){
   string str;
   Console.WriteLine("Enter any subject...");
   str = Console.ReadLine();
   Console.WriteLine("Entered subject ="+str);
 }
}

输出量

这将产生以下输出-

1
2
Enter any subject...
Entered subject = Maths