Phương thức ReadLine () được sử dụng để đọc một dòng từ bảng điều khiển trong C #.
str = Console.ReadLine();
Ở trên sẽ đặt dòng trong biến str.
Ví dụ
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);
}
} Đầu ra
Input =
Ở trên, chúng tôi đã hiển thị một dòng bằng phương thức Console.ReadLine (). Chuỗi được nhập bởi người dùng từ dòng lệnh.