Is there a reason why I can't use the following code?
ulong test(int a, int b)
{
return a == b ? 0 : 1;
}
It shows me:
Cannot implicitly convert type 'int' to 'ulong'. An explicit conversion exists (are you missing a cast?)
The following will work:
ulong test(int a, int b)
{
return false ? 0 : 1;
}
I know how to solve the problem. I just want to know the reason.
Thanks.
false
withtrue
? Maybe there's some reason that1
can be implicitly converted by0
can't? – Playerfalse ? 0 : 1
is constant expression. Thatreturn a == b ? 0 : 1
is not. Constant expression of typeint
allowed be converted implicitly toulong
if it fit inulong
range. – Brevereturn 1
– Andersen