Console.ResetColor() Method in C#

Console.ResetColor() Method is used to the foreground and background console colors to their defaults i.e. background to black and foreground to white.

Syntax:

public static void ResetColor ();

Exceptions:

  • SecurityException: If the user does not have permissions to peform the action.
  • IOException: If an I/O error occurred.

Below programs illustrate the use of the above-discussed method:

Example 1: Setting the console colors to red and yellow

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to set the colors to red and yellow
// to demostrate ResetColor() in next example
using System;
  
namespace GFG {
  
class Program {
  
    // Main Method
    static void Main(string[] args)
    {
        // using BackgroundColor property
        Console.BackgroundColor = ConsoleColor.Yellow;
  
        // using ForegroundColor property
        Console.ForegroundColor = ConsoleColor.Red;
  
        Console.WriteLine("Welcome to GeeksForGeeks");
    }
}
}

chevron_right


Output:

Example 2: Resetting the colors to default

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to illustrate the
// Console.ResetColor Property
using System;
namespace GFG {
  
class Program {
  
    // Main Method
    static void Main(string[] args)
    {
  
        // using ResetColor() Method
        Console.ResetColor();
  
        Console.WriteLine("Welcome to GeeksForGeeks");
    }
}
}

chevron_right


Output:

Reference:



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.