I got shocked knowing that there are no arithmetic operator +
, -
, *
, /
, and %
for 8 and 16 bit integers in C#. I am reading "C# 5.0 Pocket Reference" on page 23 as follows.
The following code does not compile.
class Program
{
static void With16Bit()
{
short a = 1;
short b = 2;
short c = a + b;
Console.WriteLine(c);
}
static void With8Bit()
{
byte a = 1;
byte b = 2;
byte c = a + b;
Console.WriteLine(c);
}
static void Main(string[] args)
{
With8Bit();
With16Bit();
}
}
Why did the C# designers do it? What are their consideration about it?