Saturday, October 11, 2008

Checked/Unchecked Arithmetic:

Checked/Unchecked Arithmetic:

When a value exceeds the limitations of a data type, it is said to overflow, this can sometime produce unexpected result.It can even be dangerous, particularly when using unsafe code. to prevent this type of Error C# provide two new operator. if such overflow condition in code ,it will not let that be happen and throw Exception,

(1)Checked Arithmetic: if over flow occurs in between below code Exception Occurs.

checked

{ int i = int.MaxValue; Console.WriteLine(i); i++; Console.WriteLine(i);

}

(2)Unchecked Arithmetic: any overflow in unchecked operator will simply truncated.

unchecked

{

int i = int.MaxValue; Console.WriteLine(i); i++; Console.WriteLine(i);

}

Fore more detail please visit.

http://www.blackwasp.co.uk/CheckedArithmetic.aspx

No comments:

Post a Comment

Comments posted on ASP.Net Ajax Tutorials Blog are moderated and will be approved only if they are on-topic and not abusive. Please email me or my team for tech-support or blogging related questions. Avoid including website URLs in your comments - Thanks Author