Console Class in C#

CsharpServer Side ProgrammingProgramming

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("\nForeground 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("\nForeground color changed = "+Console.ForegroundColor);
      Console.CursorSize = 1;
      Console.WriteLine("\nCursorSize = "+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
raja
Published on 14-Nov-2019 10:11:07
Advertisements