<分区>
知道没有算术运算符 +
、-
、*
、/
和%
用于 C# 中的 8 位和 16 位整数。我正在阅读第 23 页上的“C# 5.0 Pocket Reference”,如下所示。
以下代码无法编译。
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();
}
}
为什么 C# 设计者要这样做?他们对此有何考虑?