2
Reply

What are the 2 use of using statement in C#?

Gaurav Mishra

Gaurav Mishra

11y
1.7k
0
Reply

    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(); }

    1: To import the namespace

    2: To close the connection property