This is almost a duplicate. How to fix CA2000 IDisposable C # compiler warning when using global cache . Perhaps this should be seen as a duplicate of this. I'm not sure.
Code Analysis , , IDisposable, , . , DataTable DataTable usersDS.Table ( ).
, , IMHO CA. , CA, , , .
, no & hellip, , . :
DataTable dataTable = null;
DataColumn dataColumn1 = null, dataColumn2 = null;
try
{
dataColumn1 = new DataColumn() { ColumnName = "Handle", DataType = typeof(string) };
dataColumn2 = new DataColumn() { ColumnName = "Nickname", DataType = typeof(string) };
dataTable = new DataTable()
{
TableName = "Users",
Columns = { dataColumn1, dataColumn2 }
};
usersDS.Tables.Add(dataTable);
}
catch
{
if (dataTable != null)
{
dataTable.Dispose();
}
if (dataColumn1 != null)
{
dataColumn1.Dispose();
}
if (dataColumn2 != null)
{
dataColumn2.Dispose();
}
throw;
}