如何在 C# 中读取字符串形式的输入?
若想在 C# 中读取字符串形式的输入,请使用 Console.ReadLine() 方法。
str = Console.ReadLine();
以上示例将读取字符串形式的输入。我们无需在此使用转换方法,因为输入默认采用字符串形式。
现在显示用户输入的字符串 −
示例
using System;
using System.Collections.Generic;
class Demo {
static void Main() {
string myStr;
// use ReadLine() to read the entered line
myStr = Console.ReadLine();
// display the line
Console.WriteLine("Result = {0}", myStr);
}
}输出
Result =
以下为输出结果。假设用户输入了“Amit”作为输入 −
Result = amit
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP