我有以下带有六个 CA2000 警告的代码。我在进行代码分析时收到此警告。请让我知道如何克服这个警告以及为什么我会收到这个警告。请帮助我如何清除此警告并提前感谢。
if (e.Row.RowType == DataControlRowType.Footer)
{
decimal num3 = 0;
foreach (GridViewRow gridViewRow in this.gvTax.Rows)
{
Label label2 = gridViewRow.FindControl("lbltax") as Label;
num3 += Convert.ToDecimal(label2.Text);
}
int count = e.Row.Cells.Count;
for (int i = 0; i <= count - 1; i++)
{
e.Row.Cells[i].Visible = false;
}
TableHeaderCell tableHeaderCell = new TableHeaderCell();
tableHeaderCell.Text = "Total Commission";
tableHeaderCell.ColumnSpan = 1;
tableHeaderCell.HorizontalAlign = HorizontalAlign.Center;
tableHeaderCell.VerticalAlign = VerticalAlign.Middle;
e.Row.Cells.AddAt(0, tableHeaderCell);
tableHeaderCell = new TableHeaderCell();
tableHeaderCell.Text = Math.Round(num, 2).ToString();
tableHeaderCell.ColumnSpan = 1;
tableHeaderCell.HorizontalAlign = HorizontalAlign.Center;
tableHeaderCell.VerticalAlign = VerticalAlign.Middle;
e.Row.Cells.AddAt(1, tableHeaderCell);
tableHeaderCell = new TableHeaderCell();
tableHeaderCell.Text = "Net Commission";
tableHeaderCell.ColumnSpan = 1;
tableHeaderCell.HorizontalAlign = HorizontalAlign.Center;
tableHeaderCell.VerticalAlign = VerticalAlign.Middle;
e.Row.Cells.AddAt(2, tableHeaderCell);
tableHeaderCell = new TableHeaderCell();
tableHeaderCell.Text = Math.Round(num - num3, 2).ToString();
tableHeaderCell.ColumnSpan = 1;
tableHeaderCell.HorizontalAlign = HorizontalAlign.Center;
tableHeaderCell.VerticalAlign = VerticalAlign.Middle;
e.Row.Cells.AddAt(3, tableHeaderCell);
tableHeaderCell = new TableHeaderCell();
tableHeaderCell.Text = "Total Deduction";
tableHeaderCell.ColumnSpan = 1;
tableHeaderCell.HorizontalAlign = HorizontalAlign.Center;
tableHeaderCell.VerticalAlign = VerticalAlign.Middle;
e.Row.Cells.AddAt(4, tableHeaderCell);
tableHeaderCell = new TableHeaderCell();
tableHeaderCell.Text = Math.Round(num3, 2).ToString();
tableHeaderCell.ColumnSpan = 1;
tableHeaderCell.HorizontalAlign = HorizontalAlign.Center;
tableHeaderCell.VerticalAlign = VerticalAlign.Middle;
e.Row.Cells.AddAt(5, tableHeaderCell);
}
}
警告如下。
01 ) 警告 1 CA2000:Microsoft.Reliability:在方法“Pay.gvTax_RowDataBound(object, GridViewRowEventArgs)”中,对象“tableHeaderCell”未沿所有异常路径处理。在对对象“tableHeaderCell”的所有引用超出范围之前调用 System.IDisposable.Dispose。
02) 警告 2 CA2000:Microsoft.Reliability:在方法“Pay.gvTax_RowDataBound(object, GridViewRowEventArgs)”中,对象“tableHeaderCell”未沿所有异常路径处理。在对对象“tableHeaderCell”的所有引用超出范围之前调用 System.IDisposable.Dispose。
03) 警告 4 CA2000:Microsoft.Reliability:在方法“Pay.gvTax_RowDataBound(object, GridViewRowEventArgs)”中,对象“tableHeaderCell”未沿所有异常路径处理。在对对象“tableHeaderCell”的所有引用超出范围之前调用 System.IDisposable.Dispose。
04) 警告 4 CA2000:Microsoft.Reliability:在方法“Pay.gvTax_RowDataBound(object, GridViewRowEventArgs)”中,对象“tableHeaderCell”并未沿所有异常路径进行处理。在对对象“tableHeaderCell”的所有引用超出范围之前调用 System.IDisposable.Dispose。
05) 警告 5 CA2000:Microsoft.Reliability:在方法“PayCommission.gvCommissionTax_RowDataBound(object, GridViewRowEventArgs)”中,对象“tableHeaderCell”未沿所有异常路径进行处理。在对对象“tableHeaderCell”的所有引用超出范围之前调用 System.IDisposable.Dispose。
06) 警告 6 CA2000:Microsoft.Reliability:在方法“PayCommission.gvCommissionTax_RowDataBound(object, GridViewRowEventArgs)”中,对象“tableHeaderCell”未沿所有异常路径进行处理。在对对象“tableHeaderCell”的所有引用超出范围之前调用 System.IDisposable.Dispose。