Jon: I've changed the code as you suggested. When I use the setColours method
in a class constructor I am inserting the ConsoleColor names i.e. Black,
Yellow as the actual parameters. Is this correct? I am getting an error 'The
name 'Black' does not exist in the current context' (same message for Yellow.)
I don't think this is a scope-related error since I've got similar methods
and parameters in the same Utilities class where the setColours is defined.
"Jon Skeet [C# MVP]" wrote:
Paolo <Pa***@discussions.microsoft.comwrote:
I have the following:
void setColours()
{
Console.BackgroundColor = ConsoleColor .Black;
Console.ForegroundColor = ConsoleColor.Yellow;
}
thus setting the colours at compile time.
I would like to set the colours at run time and have something like:
void setColours( bgColour, fgColour)
{
Console.BackgroundColor = ConsoleColor .bgColour;
Console.ForegroundColor = ConsoleColor.fgColour;
}
however the compiler does not allow this.
Is it possible to set colours at run time and if so how would i do it?
You just need to change your code to give types to the parameters:
void setColours(ConsoleColor bgColour, ConsoleColor fgColour)
{
Console.BackgroundColor = bgColour;
Console.ForegroundColor = fgColour;
}
--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com