Click here to Skip to main content
15,884,176 members
Articles / Programming Languages / C#
Alternative
Tip/Trick

The goto-less goto!

Rate me:
Please Sign up or sign in to vote.
4.00/5 (4 votes)
7 Feb 2011CPOL 9.8K   2   3
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)


Written By
Software Developer (Senior)
Sweden Sweden
I make software.

Comments and Discussions

 
GeneralSorry, I assumed you were going to use exceptions for your r... Pin
Wolfgang_Baron10-Feb-11 4:37
professionalWolfgang_Baron10-Feb-11 4:37 
GeneralPerformance would greatly suffer? For using the RAII idiom? ... Pin
Jörgen Sigvardsson9-Feb-11 7:17
Jörgen Sigvardsson9-Feb-11 7:17 
GeneralReason for my vote of 2 While your code would look nice, per... Pin
Wolfgang_Baron9-Feb-11 4:44
professionalWolfgang_Baron9-Feb-11 4:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.