Integer overflow C# with Example



Integer overflow C# with Example

There is a maximum capacity an integer can store. And when you go over that limit, it will loop back to the negative 
side. For int, it is 2147483647 
int x = int.MaxValue; //MaxValue is 2147483647 
//make operation explicitly unchecked so that the example also 
x = unchecked(x + 1); 
works when the check for arithmetic overflow/underflow is enabled in the project settings 
Console.WriteLine(x); //Will print -2147483648 
Console.WriteLine(int.MinValue); //Same as Min value 
For any integers out of this range use namespace System.Numerics which has datatype BigInteger. Check below 
link for more information https://msdn.microsoft.com/en-us/library/system.numerics.biginteger(v=vs.110).aspx 

0 Comment's

Comment Form

Submit Comment