Interviews2 answers
What are the 2 use of using statement in C#?
2 Answers
There are more than 2 uses.
1. To import the namespace e.g. using System;
2. To create an alias e.g. using connection= System.Data.Common.DbConnection;
3. To wrap the disposing of an IDisposable in a Try/ Finally block to ensure Dispose is called on the IDisposable
IDisposable d = new DisposableObject();
try
{
....
}
finally
{
d.Dispose();
}
Dominic RobertsPosted Nov 5, 2013, 12:07 PM EST
1: To import the namespace
2: To close the connection property
Gaurav MishraPosted Oct 29, 2013, 5:11 AM EDT
