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 perform 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
csharp
// C# program to set the colors to red and yellow // to demonstrate 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" );
}
} } |
Output:
Example 2: Resetting the colors to default
csharp
// 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" );
}
} } |
Output:
Reference:
Article Tags :