M
Mike Ruane-Torr
Today's competition is to explain my compiler error. Here's the code:
enum RecType
{
Start,
// etc.
}
byte[] ret = new byte[17];
int pos = 0;
RecType Type;
..
..
..
ret[pos++] = (Type == RecType.Start ? 0x1 : 0x2); // ERROR
The error is:
"Cannot implicitly convert type 'int' to 'byte'"
What, even when the range of possible values can be determined at compile
time? Hmm...
Interestingly, the following compiles OK:
ret[pos++] = 0x2; // OK
enum RecType
{
Start,
// etc.
}
byte[] ret = new byte[17];
int pos = 0;
RecType Type;
..
..
..
ret[pos++] = (Type == RecType.Start ? 0x1 : 0x2); // ERROR
The error is:
"Cannot implicitly convert type 'int' to 'byte'"
What, even when the range of possible values can be determined at compile
time? Hmm...
Interestingly, the following compiles OK:
ret[pos++] = 0x2; // OK