c# - How to validate huge number of columns efficiently -


i have below datatable can have number of rows , column in each row around 40. trying validate each column , if fails copying row in new table.

private void validaterows(datatable csvdatatable) {     datatable invalidatedtable = new datatable();     invalidatedtable = csvdatatable.clone();      // loop on rows in datatable     foreach (datarow row in csvdatatable.rows)     {         bool invalidated = false;          if (row["id"].tostring() == "")         {             invalidated = true;             row["id"] = "not valid";         }         if (row["name"].tostring() != "test")         {             invalidated = true;         }         //and rest of validation          //if invalid         if (invalidated)         {                        invalidatedtable.rows.add(row.itemarray);         }     } // end loop   } 

if there efficient way can validation? pattern can apply validating row looks cleaner?

thanks

you checking every column, if earlier columns have invalidated row. if expecting lot of invalidated rows, impact performance.

if checks don't have side effects (like name check), feel free skip it.

if (!invalidated && row["name"].tostring() != "test") {     invalidated = true; } 

without more details on means row invalid, i'm not sure if there more can do.


Comments