我有一個對象是在給出CA2000警告的類級別聲明的。我如何擺脫下面代碼中的CA2000警告?關於級別對象的CA2000警告
public partial class someclass : Window
{
System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog()
{
AddExtension = true,
CheckFileExists = true,
CheckPathExists = true,
DefaultExt = "xsd",
FileName = lastFileName,
Filter = "XML Schema Definitions (*.xsd)|*.xsd|All Files (*.*)|*.*",
InitialDirectory = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop),
RestoreDirectory = true,
Title = "Open an XML Schema Definition File"
};
}
該警告是 - ')的新的OpenFileDialog(' 警告CA2000在方法 'SIMPathFinder.SIMPathFinder()',對象不被沿所有的異常路徑設置。調用System.IDisposable.Dispose對象的新OpenFileDialog()'之前,所有對它的引用超出範圍。
你的意思是解決警告的原因?或隱藏它,所以它不顯示? –