I believed it would be easy but cannot solve this using Console output:
I have an enum of four constants. Every time I push key "T" one of them should be shown at the screen in their established sequence.
Should I use something like MyEnum(index) every time, being index an int going through 0, 1, 2, 3, 0, 1, and so on?
Really at lost
Posted Mar 10, 2009, 12:58 PM
enum MyEnum : int
{
EnumValOne,
EnumValTwo,
EnumValThree
}
then when you want to cast it, just cast it like you would normally:
int myEnumAsInteger = (int)MyEnum.EnumValTwo;
Agustin FerrariPosted Mar 11, 2009, 1:19 PM
Quoting myself:
to change the background color of the console, one change every time I press "T" (or any key previously designed for the case).
Anand GuptaPosted Mar 11, 2009, 11:26 AM
Agustin FerrariPosted Mar 10, 2009, 5:00 PM
Sorry Brandon,
I was posing the wrong question because I had a wrong idea of how to solve what I need: to change the background color of the console, one change every time I press "T".
I wrote this:
case ConsoleKey.T: if (pointer > 14)pointer = 0;
elsepointer += 1;
Console.BackgroundColor = pointer; break;The compiler refuses to compile saying: "You cannot convert implicitly int in System.ConsoleColor. There is an explicit conversion already. Check if a conversion is missing".
I am translating from Spanish, I hope faithfully enough.
BTW if I try to force it like this:
Console.BackgroundColor = 4; (or any value in the range) I get the same message.
I am sure I do not need ConsoleColor enum for this but I cannot make it work.
Sorry for the mess!!
Agustin FerrariPosted Mar 10, 2009, 5:20 AM
Well, I think it is not what I am actually looking for, Brandon. Not all shown in a row. I need kind of a "pointer" that EVERY time I push "T", points to the next value which is then shown in the screen or acted upon.
Just one until I press that key again.
BTW, what is the way to convert those "pointers" into common types like byte, int or whatever I want?
I regret my background in all this is so bad.
Thanks for replying.
Posted Mar 10, 2009, 12:58 AM
{
// Do whatever based on myEnum
}
Will that work for you?