NET - Explain why we should close and dispose resources in a Finally block instead of Catch block

Explain why we should close and dispose resources in a Finally block instead of Catch block.

Catch block gets called only when an exception occurs or is explicitly thrown but we need to release our resources in either case (task failure or success). Finally block gets called irrespective of what happens in try. For example: we fetch data from database. In this case the first step would be creating a connection in order to access the database. Once our work is done successfully or if our logic crashes we need to end the connection so we write it in a finally block.
NET - What is an Interface in NET?
What is an Interface in NET? - Interface contains only the declaration for its abstract members (events, methods, properties)......
NET - Define most commonly used interfaces in Net Framework
Define most commonly used interfaces in .Net Framework - IComparable, IDisposable, IConvertible, ICloneable, IEquatable, IFormattable......
NET - Explain how to create and consume a Generic type.
Answer - Explain how to create and consume a Generic type.....
Post your comment