Pro EP 99 : What is better way to dispose resources ?

Muhammad Waseem
Become .NET Pro !
Dec 30, 2023

--

What is better way to dispose resources ?

Using try-catch is common practice to handle exceptions in development.

Sometime we need to dispose the resources and we add a finally block .

We can make our code cleaner by using the “using” statement, especially when dealing with resources that need disposal.

If your try-finally block only disposes resources, switch to the concise new 𝐮𝐬𝐢𝐧𝐠 𝐬𝐲𝐧𝐭𝐚𝐱 for cleaner code.

Even with new syntax we don’t even need braces for using.

Whenever you’re ready, there are 3 ways I can help you:

  1. Promote yourself to 8700+ subscribers by Sponsoring my Newsletter
  2. Get a FREE eBook from Gumroad that contains 30 .NET Tips (3K+ downloads)
  3. Become a Patron (If my content was helpful) and get access to 180+ .NET Questions and Answers

--

--