4

The Resource Acquisition Is Initialization (RAII) idiom and the try-finally statement form the backbone of the traditional approaches to writing exception safe programming.

My question is: Is there something like Scope Guard Statement available on C#?

Glauco Vinicius
  • 2,527
  • 3
  • 24
  • 37

1 Answers1

3

There's not a direct translation of the scope guard idiom built into C# or in the BCL, but Alex Rønne Petersen wrote up a blog post with a solution that leverages the IDispoable interface and C#'s using statements to do something similar to what you're looking for.

Adam Maras
  • 26,269
  • 6
  • 65
  • 91