Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

Working with Checked and UnChecked Keywords in .Net 2.0.

Author: DevAsp Team
Download Source Code : 701_Checked And unchecked.zip

In this article you will learn working with checked and unchecked keywords in .net 2.0 using c#.

Checked key word is used to enforce the compiler to check the buffer overflow while operating arithmetic operators. If there is any Buffer overflow code will throw exception.

 

 static void Main(string[] args)

        {

//Intger

            int _value1 = 1500056564;

            int _value2 = 1200046565;

            checked

            {

// this Code will give exception BuferOverflow

                        System.Console.WriteLine(_value1 * _value2);                System.Console.Read();

 

            }

 

And Unchecked is used to enforce the compiler to do not check that is there any buffer overflow or Not. If here any Buffer overflow is occurred it will just truncate the value but not throw exception.

 

  static void Main(string[] args)

        {

 //Intger

            int _value1 = 1500056564;

                                    int _value2 = 1200046565;

            unchecked

            {

// This Code will Not Give Exception

 

             System.Console.WriteLine(_value1 * _value2);               

System.Console.Read();

            }

Article Comments
Hi frnd
Thanx for ur valuable information.

Posted on 4/16/2010 7:31:54 AM by Rajani

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Handle Nullable Types in .Net 2.0.

Disclaimer - Privacy
© 2002-2017 DevASP.net