SIGN UP MEMBER LOGIN:    
ARTICLE

Using Statement in C#

Posted by Matt Aghnianejad Articles | How do I February 09, 2009
This article is about Using statement and how it has been implemented.
Reader Level:

You have probably used using statement a lot,here I want to write about how it has been implemented.

In the using statement,you initialize an object and save its reference in a variable . Then you access the variable via code contained inside using's braces.When you compile the code , the compiler automatically emits the try and finally blocks.

Inside the finally block,the compiler emits code to cast the object to an IDisposable and calls the Dispose method.

Obviously,the compiler allows the using statement to be used only with types that implement the IDisposable interface.

The using statement also works with value types that implement the IDisposable interface.This allows you to create an extremely efficient and useful mechanism to encapsulate the code necessary to begin and end an operation.

Here is one more article on using statement with sample code:

http://www.c-sharpcorner.com/UploadFile/DipalChoksi/UsingStatement11092005065819AM/UsingStatement.aspx

Login to add your contents and source code to this article
share this article :
post comment
 
Nevron Gauge for SharePoint
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Team Foundation Server Hosting
Become a Sponsor