Assigning Value to a variable that is too big for it! (checked and unchecked concept)

Posted by ThickBook on Stack Overflow See other posts from Stack Overflow or by ThickBook
Published on 2010-06-18T11:07:12Z Indexed on 2010/06/18 11:13 UTC
Read the original article Hit count: 162

Filed under:
|

So when we assign a value to a variable then that variable should be able to hold it, right? and if not compiler produces the error. Now there is an option in C# known as Checked (which is by default) and unchecked option. But is there practical use of unchecked? any comments for a layman? :)

Example:

int a=int.MaxValue;
int b=int.MaxValue;

unchecked
{
   int sum=a+b;
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about beginner