如何在 C# 中从控制台读取一行?
ReadLine() 方法用于在 C# 中从控制台读取一行。
str = Console.ReadLine();
上述代码会将行设置在变量 str 中。
示例
using System;
using System.Collections.Generic;
class Demo {
static void Main() {
string str;
// use ReadLine() to read the entered line
str = Console.ReadLine();
// display the line
Console.WriteLine("Input = {0}", str);
}
}输出
Input =
以上内容中,我们使用 Console.ReadLine() 方法显示了一行。字符串由用户从命令行输入。
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP