I would like to know if there are ways to make this run faster. Not a big concern right now, but I would like to think long term, it might be important.
This is C#, and I can not change the input parameters data types, but basically I have to make something like the SQL: SELECT returnCol FROM dt WHERE ColName = ColValue
As the datatable itself: it has more than 100 columns, but it should not too many rows, usually ~10 rows but it can spike up to 100 rows sometimes. This is part of a data parse that is happening once a minute, that is why I am trying to see if there are ways for enhancement.
private string FindInT(DataTable dt, string ColName, string ColValue, string returnCol)
{
foreach (DataRow row in dt.Rows)
{
if (row[ColName].ToString().ToLower().Trim() == ColValue.ToLower().Trim())
{
return row[returnCol].ToString();
}
}
return "";
}
RowFilter
onDataView
, or callingDataTable.Select()
) are likely to be slower - but don't take my word for it: benchmark. This sounds like a case of premature optimization. \$\endgroup\$