Console.ResetColor() Method in C#
Last Updated :
13 Jul, 2021
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
using System;
namespace GFG {
class Program {
static void Main( string [] args)
{
Console.BackgroundColor = ConsoleColor.Yellow;
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine( "Welcome to GeeksForGeeks" );
}
}
}
|
Output:
Example 2: Resetting the colors to default
csharp
using System;
namespace GFG {
class Program {
static void Main( string [] args)
{
Console.ResetColor();
Console.WriteLine( "Welcome to GeeksForGeeks" );
}
}
}
|
Output:
Reference:
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...