// This try-finally statement only calls Dispose in the finally block.
Font font1 = new Font("Arial", 10.0f);
try
{
byte charset = font1.GdiCharSet;
}
finally
{
if (font1 != null)
{
((IDisposable)font1).Dispose();
}
}
// You can do the same thing with a using statement.
using (Font font2 = new Font("Arial", 10.0f))
{
byte charset = font2.GdiCharSet;
}
C#使用using代替try-finally
推荐阅读
- python的数据处理
- 再讲一点点参数,然后科普一下
- Codeforces Round #323 (Div. 2) C. GCD Table
- Educational Codeforces Round 1(C. Nearest vectors)
- BNU 51276 - 道路修建 Small (并查集)
- HDU 1011 Starship Troopers (树dp)
- POJ 3107 Godfather (树重心)
- HDU 2256 Problem of Precision (矩阵快速幂)
- Codeforces 706 D. Vasiliy's Multiset (字典树贪心)
- POJ 3468 A Simple Problem with Integers (线段树成段更新)