Skip to content

Instantly share code, notes, and snippets.

@graylikeme
Last active August 29, 2015 13:56
Show Gist options
  • Save graylikeme/9308572 to your computer and use it in GitHub Desktop.
Save graylikeme/9308572 to your computer and use it in GitHub Desktop.
public static class Utils{
public static void Using<T>(T x, Action<T> func) where T: IDisposable
{
try {
func(x);
}catch(){
}finally{
x.Dispose();
}
}
}
void SomeFunc() {
utils.Using(new StreamReader(""), x => {
Console.WriteLine(x.ReadLine());
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment