문제

Possible Duplicate:
C# XOR on two byte variables will not compile without a cast

Why do I get a compile error in this C# code?

void test()
{
   ushort a = 0;
   ushort b = 0;
   ushort c = a ^ b; //ERROR
}

error CS0266: Cannot implicitly convert type 'int' to 'ushort'. An explicit conversion exists (are you missing a cast?)

도움이 되었습니까?

해결책

Take a look at this: C# XOR on two byte variables will not compile without a cast

Basically, with bit operators, any operand smaller than an int is automatically converted up to an int.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top