Alex Rivera | Logout

Type of conditional expression cannot be determined as

Asked 2011-04-02T18:12:50.310
24

When I compile my C# project in MonoDevelop, I get the following error:

Type of conditional expression cannot be determined as 'byte' and 'int' convert implicitly to each other

Code Snippet:

byte oldType = type;
type = bindings[type];
//Ignores updating blocks that are the same and send block only to the player
if (b == (byte)((painting || action == 1) ? type : 0))
{
    if (painting || oldType != type) { SendBlockchange(x, y, z, b); } return;
}

This is the line that is highlighted in the error:

if (b == (byte)((painting || action == 1) ? type : 0))

Help is greatly appreciated!

Edit
Report

1 Answer

32

The conditional operator is an expression and thus needs a return type, and both paths have to have the same return type.

(painting || action == 1) ? type : (byte)0
answered 2011-04-02T18:14:40.977

Your Answer