Console Class in C#


The Console class in C# is used to represent the standard input, output, and error streams for console applications.

Let us see some examples of Console class properties in C# −

Console.CursorLeft property

To change the CursorLeft of the Console in C#, use the Console.CursorLeft property.

Example

Let us see an example −

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("
Foreground color changed = "+Console.ForegroundColor);       Console.CursorLeft = 30;       Console.Write("CursorLeft position: "+Console.CursorLeft);    } }

Output

This will produce the following output −

Console.CursorSize property

To change the CursorSize of the Console in C#, use the Console.CursorSize property in C#.

Example

Let us see an example −

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("
Foreground color changed = "+Console.ForegroundColor);       Console.CursorSize = 1;       Console.WriteLine("
CursorSize = "+Console.CursorSize);    } }

Output

This will produce the following output −

Console.BufferWidth property

To change the BufferWidth of the Console, use the Console.BufferWidth property.

Example

Let us now see an example −

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);
   }
}

Output

This will produce the following output −

Buffer Height = 200
Buffer Width = 200

Updated on: 14-Nov-2019

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements