I'm using this to go through my column headers. Columns that don't equal or contain columnsToKeep are removed. Problem is the DataTable has 100+ columns, so this takes a long time. Is there a faster way of accomplishing this?
var columnsToKeep = new List<string>() { "Summary", "Status", "CF1" };
var toRemove = new List<DataColumn>();
foreach (DataColumn column in dtTable.Columns)
{
if (!columnsToKeep.Any(name => column.ColumnName == name) && !columnsToKeep.Any(name => column.ColumnName.Contains("CF1")))
{
toRemove.Add(column);
}
}
toRemove.ForEach(col => dtTable.Columns.Remove(col));