Hi,
I know I can set property ForegroundColor of consele but what I am not sure is: the property is of the type enum
or ConsoleColor, which is enum? I just do not know what I am exactly doing, setting the property to value of consolecolor (what is this, instance of enum? enum?).
Thanks
views:
40answers:
1
A:
The property is of type ConsoleColor
, which is an enum type.
When you set it with something like:
Console.ForegroundColor = ConsoleColor.Red;
you're setting it to a value of type ConsoleColor
- just like anything else. ConsoleColor.Red
is a value of type ConsoleColor in the same way that 3 is a value of type int
and "hi"
is a value of type string
(although in the latter case it's a reference to an object, whereas enums are value types).
In particular, you have to set it to a value of type ConsoleColor
rather than any other enum. For example, this won't compile:
// This would be crazy
Console.ForegroundColor = FileShare.ReadWrite;
Jon Skeet
2010-10-14 21:20:25
So, I need to set this property of any value of the Console.Color, which means to some of its constants, ok?
Mojmi
2010-10-14 21:23:17
@Mojmir: Not `Console.Color`, `ConsoleColor` - very different.
Jon Skeet
2010-10-14 21:45:52