Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#

The goto-less goto!

4.00/5 (4 votes)
7 Feb 2011CPOL 10.5K  
Usually, gotos are used to clean up resources when exiting a function. I would recommend using the RAII[^] idiom. It also works works well in the presence of exceptions.For C# I would use IDisposable/using. If that's not possible, I'd use a finally clause to clean up.Everything else...
Usually, gotos are used to clean up resources when exiting a function. I would recommend using the
RAII[^] idiom. It also works works well in the presence of exceptions.

For C# I would use IDisposable/using. If that's not possible, I'd use a finally clause to clean up.

Everything else will eventually end up being messy.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)