我是一位開發人員,他正在維護並不斷更快更好地製作應用程序。我碰到一段使用.Dispose()
的代碼,它位於using
聲明中。多次處置對象
下面是代碼:
using (IDbCommand cmd = proxy.Connection.CreateCommand())
{
cmd.CommandText = "usp_GetPluginInfo";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(proxy.Connection.CreateParameter(cmd, "@dealershipId", dealershipId));
cmd.Parameters.Add(proxy.Connection.CreateParameter(cmd, "@pluginId", pluginId));
PluginInfo[] pluginInfos = PopulatePluginsFromCommand(cmd);
result = pluginInfos.First();
cmd.Dispose();
}
豈不最後}
處置當命令完成?在這種情況下,我認爲沒有必要使用Dispose()
。
非常感謝您的幫助!
重複的問題:是不是多餘的在自己的內部使用塊處理對象?](http://stackoverflow.com/questions/10683086/isnt-it-redundant-to-dispose-of-an-object-inside-its-own-using-block ) – Logarr
你是對的。 – EkoostikMartin