Best way to handle Integer overflow in C#?

Posted by byte on Stack Overflow See other posts from Stack Overflow or by byte
Published on 2010-06-02T04:13:03Z Indexed on 2010/06/02 4:23 UTC
Read the original article Hit count: 437

Filed under:
|
|
|

Handling integer overflow is a common task, but what's the best way to handle it in C#? Is there some syntactic sugar to make it simpler than with other languages? Or is this really the best way?

int x = foo();
int test = x * common;
if(test / common != x)
    Console.WriteLine("oh noes!");
else
    Console.WriteLine("safe!");

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET