Click here to Skip to main content
15,888,202 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
please let me know the use of "Using" keyword in asp.net with small example
Posted
Comments
vinay.tatipamula 1-Aug-13 5:48am    
The reason for the "using" statement is to ensure that the object is always disposed correctly, and it doesn't require explicit code to ensure that this happens.
vinay.tatipamula 1-Aug-13 5:49am    
check the example.
[no name] 1-Aug-13 5:51am    
You are not going to learn how to program asking one question at a time on a message forum. You need to get yourself a book on programming and go through it, find some tutorials and work through them or take a class.
Ankur\m/ 1-Aug-13 7:40am    
http://www.lmgtfy.com/?q=using+asp.net

C#
using (SomeClass obj= new SomeClass())
{
    obj.DoSomething();
}

to

{ // limits scope of obj
    SomeClass obj= new SomeClass();
    try
    {
        obj.DoSomething();
    }
    finally
    {
        // Check for a null resource.
        if (obj!= null)
            // Call the object's Dispose method.
            ((IDisposable)obj).Dispose();
    }
}
 
Share this answer
 
Refer - using (C# Reference)[^].
Quote:

The using keyword has two major uses:



  • As a directive, when it is used to create an alias for a namespace or to import types defined in other namespaces. See using Directive.


  • As a statement, when it defines a scope at the end of which an object will be disposed. See using Statement.



 
Share this answer
 
Understanding the 'using' statement in C#[^]

The "using" Keyword in C#[^]

Check the links..explanation with detailed example..
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900