Last active
August 29, 2015 13:56
-
-
Save graylikeme/9308572 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class Utils{ | |
public static void Using<T>(T x, Action<T> func) where T: IDisposable | |
{ | |
try { | |
func(x); | |
}catch(){ | |
}finally{ | |
x.Dispose(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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