What are the uses of "Using" keyword in C#?
Manas Mohapatra
Select an image from your device to upload
To allow the normal use of types in a namespace, using System.IO;To create an alias for a namespace or a type. This is called a using alias directive.using myp = System.Data;The using statement ensures that Dispose() is called even if an exception occurs when you are creating objects and calling methods, properties and so on. Dispose() is a method that is present in the IDisposable interface that helps to implement custom Garbage Collection. In other words, if I am doing some database operation (Insert, Update, Delete) but somehow an exception occurs, then here the using statement closes the connection automatically. here’s no need to call the connection Close() method explicitly.
using (SqlConnection conn = new SqlConnection(connString))