Answers for "c# byte + byte is int"

C#
0

c# byte + byte is int

byte i = 10;
byte k = 25;
//The below returns an int
Console.WriteLine((i + k).GetType());
//This is because of number promotion and the fact that all integral types
//below 32 bits don't seem to have their respective arithmetic operators
Console.WriteLine((byte)(i + k));
//Seems your stuck with this ^^. Which unfortunately doesn't detect overflow
Posted by: Guest on March-02-2022

C# Answers by Framework

Browse Popular Code Answers by Language