Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C#

คลาส Console ใน C#


คลาส Console ใน C# ใช้แทนสตรีมอินพุต เอาต์พุต และข้อผิดพลาดมาตรฐานสำหรับแอปพลิเคชันคอนโซล

มา看看ตัวอย่างคุณสมบัติต่างๆ ของคลาส Console ใน C#

คุณสมบัติ Console.CursorLeft

ใช้คุณสมบัติ Console.CursorLeft เพื่อเปลี่ยนตำแหน่งแนวนอนของเคอร์เซอร์ใน 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.CursorLeft = 30; 
        Console.Write("CursorLeft position: " + Console.CursorLeft); 
    } 
}

ผลลัพธ์

คลาส Console ใน C#

คุณสมบัติ Console.CursorSize

ใช้คุณสมบัติ 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 ใน C#

คุณสมบัติ Console.BufferWidth

ใช้คุณสมบัติ 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