Hi,
I wrote a simple program to check the implicit conversion. I was under impression that I should be able to convert byte to short or ushort. But when I compile following program I get an error saying - error CS0266: Cannot implicitly convert type 'int' to 'ushort'. An explicit conversion exists (are you missing a cast )
Can someone tell me what am I doing wrong here
Thanks,
green
using System;
public class Demos
{
public static void Main()
{
byte b2 = 125;
byte b3 = 200;
ushort i = b2 + b3;
Console.WriteLine(i);
}
}

Getting error while converting byte to ushort
bilsa
im unsure if this will give you the correct result but try using the Convert.UInt32() class/method:
......Convert.UInt32(b1 + b2);
Zuchman
As far as i can remember, in addition all the operands are implicitly converted to a single type int(or an another type which i can't recollect).
So in ur case although b2, b3 are byte in the statement b2 + b3, they are converted into int and then added, so the result is int. U are assigning int to ushort which is type narrowing, so its not allowed