Interviews2 answers
What is using keyword in C#?
2 Answers
using keyword is used Remove unused memory form the object
Using(SqlConnection objConn=new SqlConnection())
{
}
Ananth GPosted Oct 21, 2016, 12:05 AM EDT
There are two usage of "using" keyword
1. to import namespaces
e.g using System;
using System.IO;
2. to handle unmanaged resources
An object inside or outside the .NET Framework, which uses external code (For example: file handles, streams, DB connections). The Garbage Collector can't handle unmanaged resources, so we need to release them manually.
e.g using (Stream input = File.OpenRead(filename))
{
...
}
This can only be used with types that implement IDisposable.
Smita JagtapPosted Jul 14, 2013, 9:42 PM EDT
