By default, C# will not check arithmetic for overflow.
Using this code as an example:
//example.cs
class Example
{
static void Main()
{
int number = int.MaxValue;
Console.Writeline(++number)
}
}
Suppose: number == -2147483648 ----> It will not get any error message.
If you're getting the System.OverflowException, your arithmetic overflow checking is turned on ( Ex.: c:\ csc /checked+ example.cs).
Solution 1 : Try turning it off .
Example:
c:\ csc /checked- example.cs -- will wrap the int value to int.MinValue and not cause the System.Overflow Exception.
Solution 2: Use Uncheck Statement
//example.cs
class Example
{
static void Main()
{
unchecked ---> all statements are never checked for arithmetic overflow
{
int number = int.MaxValue;
Console.Writeline(++number)
}
}
}
Solution 3: use unchecked statement
//example.cs
class Example
{
static void Main()
{
int number = int.MaxValue;
Console.Writeline(unchecked(++number)); ---> expression is checked for aruthmetic overflow
}
}
Hope this helps! :D
===================
A
"Chua Wen Ching" <cw*@cwc.com> wrote in message news:07****************************@phx.gbl...
Thanks Derek...
Okay i had another question..
my program runs smoothly for the first minute, after 1
minute...
suddenly it breaks and display this error:
do you know what is the cause of this problem...
i had check my codes and confirm it is working.. shouldn't
be a problem on logic side
An unhandled exception of type 'System.OverflowException'
occurred in system.windows.forms.dll
Additional information: Overflow error.
Any help?
Regards,
Chua Wen Ching :p