Tip

2011-04-02 26 views
17
olarak tespit edilemeyen

Ben MonoDevelop benim C# projesi derleme, aşağıdaki hatayı alıyorum:Tip

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

Kod Parçacığı: Bu çizgidir

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; 
} 

o hatada vurgulanır:

Yardım büyük beğeni topluyor!

cevap

23

Koşullu işleç bir ifadedir ve bu nedenle bir dönüş türüne ihtiyaç duyar ve her iki yolun da aynı dönüş türüne sahip olması gerekir.

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

. Çok teşekkür ederim! – Jakir00

+1

Parametrenin, String.Format ("value: {0}", (value == null)?: "Null": value) 'türünde olduğu herhangi bir türde olması bekleniyor. 'int?'? – mr5

4

Orada byte ve int arasında hiçbir örtük dönüştürme, yani üçlü operatörün sonuçlarında birini belirtmek gerekir: Bu operatör üzerinde

? type : (byte)0 

Hem dönüş tipleri aynı olması ya da ihtiyaç ya da çalışmak için tanımlanmış bir örtük dönüşüm var. MSDN ?: Operator itibaren

:

mantıklı

Either the type of first_expression and second_expression must be the same, or an implicit conversion must exist from one type to the other.