Posts

Showing posts with the label arithmetic operations

C# Integral Types That Lack Arithmetic Operations

Image
In C# there's some types that lack arithmetic operations These Integral types are 8 and 16 Bit so it's converted implicitly to the largest types, below is the list of these types : byte sbyte short ushort Sample of code: short a=10,b=10; short sum = a+b; // compile time error The solution: as mentioned a and b   variables   are implicitly  converted to the largest type "Int" , to solve this we have to use the explicit casting on the total result: short a=10,b=10; short sum = (short)(a+b); // compiled successfully References: Microsoft