假设我有代码:
void Method1() {
Bitmap bitmap1;
foreach (string name in OpenFileDialog1.FileNames) {
bitmap1 = new Bitmap(name);
... // process bitmap
bitmap1.Dispose();
}
}
循环中是否需要Dispose()?
答案 0 :(得分:0)
更好的方法,因为此代码结构可以使用using
:
void Method1() {
foreach (string name in OpenFileDialog1.FileNames) {
using (var bitmap1 = new Bitmap(name))
{
... // process bitmap
}
}
}