Thuộc tính WindowWidth lấy hoặc thiết lập chiều rộng của cửa sổ console.
Khai báo biến.
int width;
Bây giờ, lấy chiều rộng cửa sổ hiện tại.
width = Console.WindowWidth;
Đoạn mã hoàn chỉnh sau là ví dụ.
Ví dụ
using System;
using System.Numerics;
using System.Globalization;
class Demo {
static void Main() {
int width;
int height;
width = Console.WindowWidth;
height = Console.WindowHeight;
Console.WriteLine("Chiều rộng cửa sổ hiện tại = " + width);
Console.WriteLine("Chiều cao cửa sổ hiện tại = " + height);
}
}
Kết quả
Chiều rộng cửa sổ hiện tại = 0 Chiều cao cửa sổ hiện tại = 0