tags:

views:

40

answers:

1

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

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
So, I need to set this property of any value of the Console.Color, which means to some of its constants, ok?
Mojmi
@Mojmir: Not `Console.Color`, `ConsoleColor` - very different.
Jon Skeet