如何在 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