เมธอด 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() ผู้ใช้ป้อนสตริงจากบรรทัดคำสั่ง