Interviews22 answers
What is the use of using statement in C#
22 Answers
Yes
Amar BhagatPosted Mar 27, 2018, 7:05 AM EDT
using statement calls "Dispose" method internally when exception occurred in any method.
Amar BhagatPosted Mar 27, 2018, 7:04 AM EDT
The reason for the "using" statement is to ensure that the object is disposed as soon as it goes out of scope, and it doesn't require explicit code to ensure that this happens.
Asfend YarPosted Mar 9, 2017, 9:24 AM EST
using statement to release all the resources automatically.
Joe WilsonPosted Dec 23, 2015, 6:00 AM EST
Auto dispose the objects ,when the execution of block completed.
and
Importing Namespaces
cool signPosted Aug 10, 2015, 2:11 AM EDT
A class which inherits from IDisposable interface and also defines Dispose method for releasing resources from memory.The same class can be used in "Using" statement.
Sreeni DonyPosted Jul 22, 2015, 1:32 AM EDT
For importing namespaces.
Sreekanth ReddyPosted Jul 10, 2015, 10:59 PM EDT
using statement is used to import the library. In C language, #include is such a header file which imports the library and under the library various function works.
using statement is the same thing.
example: using system.data.sqlclient;
this imports library of some ado.net methods
Safayat ZisanPosted Apr 17, 2015, 1:11 PM EDT
using statement is use to implement all classes and objects ,method which are define in a namespace
Pankaj Kumar ChoudharyPosted Mar 27, 2015, 8:25 AM EDT
there is 2 use using statement.
1:- Importing namespace
example:using System;
2:- dispose the object
using(SqlConnection oConnection=new SqlConnection())
{
oConnection.Open();
}
if you won't close the connection it will close the connection automatically once SqlConnection has been executed completing.
Abrar Ahmad AnsariPosted Mar 10, 2015, 2:40 AM EDT
It is used to define the statement
PRABHAKAR PANDEYPosted Jan 29, 2015, 8:40 AM EST
It's a syntax to include system file ot import namespace
Md. Raskinur RashidPosted Jan 20, 2015, 9:44 AM EST
For import the Namespace
for Close the Connection to database
Devender KhowalPosted Jan 20, 2015, 9:09 AM EST
1. Referencing Namespace
2. Deallocting objects which has implemented IDisposable Interface
Dhanik SahniPosted Oct 9, 2014, 5:40 AM EDT
If a class implements IDisposable then it will create some unmanaged resources which need to be 'disposed' of when you are finished using them.
http://stackoverflow.com/questions/75401/uses-of-using-in-c-sharp
Munesh SharmaPosted Oct 9, 2014, 1:10 AM EDT
We use using statement to release all the resources automatically.
Abhishek YadavPosted Sep 6, 2014, 5:07 AM EDT
if we r use the using then it automatically release the objects from the memory
Sunil GadedPosted Aug 28, 2014, 2:11 AM EDT
The using statement is mostly used when you need to one or more resources in a segment. The using statement obtains one or various resources, executes them and then releases the objects or resources. It is widely used in database connectivity through C#.
Using (SqlConnection conn = new SqlConnection())
{
}
When we use above block, internally the code is generated like this
SqlConnection conn = new SqlConnection()
try
{
}
finally
{
// calls the dispose method of the conn object
}
Raghav MehraPosted Aug 25, 2014, 11:36 PM EDT
When you are using an object that encapsulates any resource, you have to make sure that when you are done with the object, the object's Dispose method is called. The using statement simplifies the code that you have to write to create and then finally clean up the object.
Ankur JainPosted Aug 18, 2014, 4:21 AM EDT
The using statement automatically calls the Dispose() method on the object when leaving the scope of the using statement. using statement is more elegant way of disposing object than manual dispose
Sanjeev KumarPosted Aug 17, 2014, 12:41 AM EDT
The using statement simplifies the code that you have to write to create and then finally clean up the object. The using statement obtains the resource specified, executes the statements and finally calls the Dispose method of the object to clean up the object.
manikumar madduPosted Aug 4, 2014, 11:13 PM EDT
The using block is used to obtain a resource and use it and then automatically dispose of when the execution of block completed.
Guest UserPosted Aug 1, 2014, 6:56 PM EDT















