In C# I can assign a number (up to 255) directly to a variable of type byte:
byte red = 255;
However if I do this in a more complex statement with a conditional operator:
byte red = (redNode != null) ? byte.Parse(redNode.Value) : 255;
I get an error: "CS0266 Cannot implicitly convert type 'int' to 'byte'. An explicit conversion exists (are you missing a cast?)".
I need to explicitly do the cast to byte for the 255:
byte red = (redNode != null) ? byte.Parse(redNode.Value) : (byte)255;
Why is this cast needed?