How to use the finally statement - C#.NET

Explain how to use the finally statement by providing sample code using C#.NET.

Finally statement is executed always irrespective of any condition or error occurring in a method. It is often used to cleanup code.
Example:
public void MyMethod()
{
   try
   {
       //code to connect to database
       //code to perform action
   }
   catch (Exception ex)
   {
       //handle exception
   }
   finally
   {
        //code to disconnect database.
   }
}
Steps to create a .NET Assembly - C#.NET
Explain the steps to create a .NET Assembly - Add a project from templates called “Class Library”...
Steps to create and implement Satellite Assemblies - C#.NET
Steps to create and implement Satellite Assemblies - Satellite assemblies are resource assemblies specific to language/culture...
Purpose of ResourceManager class - C#.NET
Explain the purpose of ResourceManager class - Use ResourceManager class to retrieve resources that exist in an assembly...
Post your comment