Hi,
Its a nice question , well USING and "try{} catch{} and finally{} block " used for handling exception and cleaning the resources such as database connection and file stream, socket object etc .The USING statement make sure that resources are released even if an exception occurs .Note That the USING statement is used only for resources that implement IDisposable where as finally block can be used for any type of cleanup operation.<o:p></o:p>
<o:p> </o:p>
For database example<o:p></o:p>
public string ConnectionString = "Data Source=localhost;Integrated Security=SSPI;Initial Catalog=pubs";<o:p></o:p>
string sqlQuery="SELECT DISTINCT CurDate FROM CurMaster ORDER BY 1";<o:p></o:p>
Using( SqlDataAdapter cacheDataAdapter = new SqlDataAdapter(sqlQuery,ConnectionString);<o:p></o:p>
{<o:p></o:p>
// fetch the data and display on the screen <o:p></o:p>
}<o:p></o:p>
<o:p> </o:p>
In this example the using statement takes care of exception if any while getting data from the database .<o:p></o:p>
<o:p> </o:p>
The other example is <o:p></o:p>
using( StreamReader SampleFile = new StreamReader("C:\\MySample.Txt")){<o:p></o:p>
//read out the file in a string or pass to Business Object<o:p></o:p>
} // resource will clean here<o:p></o:p>
<o:p> </o:p>
You can do it through try{} catch{} and finally{} block also<o:p></o:p>
<o:p> </o:p>
The USING statement mostly used only for resources that implement IDisposable.
am I answer to your query :-)
Cheers
Anand<o:p></o:p>