what are the uses of "using" keyword?
what are the uses of "using" keyword?
There are multiple uses. It can also be used to define the scope of a specific object to make sure that the object is picked up by the GC as soon as the using area is exited.
Hi,
Basically there are two uses of using keyword.
1. Include the namespace in current code file which is done at top of the code like
using System.Data;
using System.Data.Sql;
2. Another use of using keyword is to dispose off objects automatically when runtime executes code outside the using block like
using(SqlConnection objConn = new SqlConnection)
{
............ your code
}
Once the runtime executes the code outside the using block SqlConnection will get closed and disposed off automatically. No need to write extra code.
Hope this help you.
---V V---
Vikas Vaidya
Please mark this post as Thanks if you find the answer useful
Hi,
The main use of using keyword is as follows,
For e.g Suppose your program is having a namespace student,
and you want this namespace add in another program, so to adding this namespace to the particular program we used using keyword.
For e.g:- using student;
now you can use the classes of student in your other program where you are giving the above statement.....
The Using Keyword used to load class file.
Hi,
Use of Using Keyword
1) To tell the compiler to acess the classes and methods in a particular namespace in currently working code .
2) Used to create using statements, which define when an object will be disposed.
1) 'Using' Key word work same as 'Import' in JAVA or VB.net with namespace to import all the methods and classes.
2) 'Using' key word is also used to limit the scope of the object within the method.