I know that I can assign a value specifically to a float by doing
float y = 4.5f;
I want to do the same thing, except as a byte. How do I do this? I’ve checked the MSDN documentation and cannot find anything related to this. Also, what is this called?
Thanks,
[Edit]
For clarity the code I’m using this on is
byte myByte = a==b?1:0;
and the error I get is
Cannot implicitly convert type ‘int’
to ‘byte?’. An explicit conversion
exists (are you missing a cast?)
Solution
byte myByte = (byte)(a==b?1:0);
The
byte,sbyte,shortandushortdata types do not have designated suffixes. However, integer literal can be assigned to variables of these data types and will be implicitly converted, assuming that the value is appropriate for storage in the variable. Just for the record here are the defined literals in C#: