คลาส Console ใน C# ใช้เพื่อแสดงอินพุต เอาต์พุต และสตรีมข้อผิดพลาดมาตรฐานสำหรับแอปพลิเคชันคอนโซล
ให้เรามาดูตัวอย่างคุณสมบัติของคลาส Console ใน C# −
คุณสมบัติ Console.CursorLeft
หากต้องการเปลี่ยน CursorLeft ของ Console ใน C# ให้ใช้คุณสมบัติ Console.CursorLeft
ตัวอย่าง
เรามาดูตัวอย่างกัน −
using System;
class Demo {
public static void Main (string[] args) {
Console.BackgroundColor = ConsoleColor.Blue;
Console.WriteLine("Background color changed = "+Console.BackgroundColor);
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("\nForeground color changed = "+Console.ForegroundColor);
Console.CursorLeft = 30;
Console.Write("CursorLeft position: "+Console.CursorLeft);
}
}
ผลลัพธ์
สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -

คุณสมบัติ Console.CursorSize
หากต้องการเปลี่ยน CursorSize ของ Console ใน C# ให้ใช้คุณสมบัติ Console.CursorSize ใน C#
ตัวอย่าง
เรามาดูตัวอย่างกัน −
using System;
class Demo {
public static void Main (string[] args) {
Console.BackgroundColor = ConsoleColor.Blue;
Console.WriteLine("Background color changed = "+Console.BackgroundColor);
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("\nForeground color changed = "+Console.ForegroundColor);
Console.CursorSize = 1;
Console.WriteLine("\nCursorSize = "+Console.CursorSize);
}
}
ผลลัพธ์
สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -

คุณสมบัติ Console.BufferWidth
หากต้องการเปลี่ยน BufferWidth ของ Console ให้ใช้คุณสมบัติ Console.BufferWidth
ตัวอย่าง
เรามาดูตัวอย่างกัน −
using System;
class Demo {
public static void Main (string[] args) {
Console.BufferHeight = 200;
Console.WriteLine("Buffer Height = "+Console.BufferHeight);
Console.BufferHeight = 250;
Console.WriteLine("Buffer Width = "+Console.BufferWidth);
}
} ผลลัพธ์
สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -
Buffer Height = 200 Buffer Width = 200