Why does C# throw casting errors when attempting math operations on integer types other than int?
问题 Consider this static test class: public static class Test { public static ushort sum(ushort value1, ushort value2) { return value1 + value2 } } This causes the following compile error, with value1 + value2 underlined in red: Cannot implicitly convert type 'int' to 'ushort'. An explicit conversion exists (are you missing a cast)? Why? 回答1: Like C and C++ before it, integers are implicitly widened when used with many operators. In this case, the result of adding two ushort values together is