我读过(在 using
Statement (C# Reference) 上)using
语句应该用于释放使用非托管资源的托管类型(如文件和字体)所使用的资源。所以开始将它与 MySql 类和相关的东西一起使用,但是如果你看一下 Windows.Forms.Form 类的对象,你会看到一个 Dispose 方法,这意味着这个类实现了 IDisposable 所以,我应该使用 像下面的情况一样对 Windows.Forms.Form 对象使用
语句?
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
using (AboutBoxProjeto about = new AboutBoxProjeto())
{
about.ShowDialog();
}
}
最佳答案
来自 http://dotnetfacts.blogspot.com/2008/03/things-you-must-dispose.html :
In .NET, a dialog form is a form opened by calling the ShowDialog() method. Unlike modeless forms, the Close method is not called by the .NET Framework when the user clicks the close form button of a dialog box or sets the value of the DialogResult property. Instead the form is hidden and can be shown again without creating a new instance of the dialog box. Because a form displayed as a dialog box is not closed, you must call the Dispose() method of the form when the form is no longer needed by your application
关于c# - 我应该使用 using 语句来创建 Windows.Forms.Form 对象吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16610142/