So I have a code that adds two integers and prints the result:
Console.WriteLine("enter number: ");
int intTemp = Convert.ToInt32(Console.ReadLine());
long sum = intTemp + 5;
Console.WriteLine($"sum is : {sum}");
But if in the console I will put the maximum value for the int type, I won't get an exception, but the result is wrong, even if I am saving the result in a long variable. Here is the output:
enter number:
2147483647
sum is : -2147483644
But if the sum variable is a long, why I am getting the wrong result?