Search DataTable by column for a specific row 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 "";
        }
I have two suggestions:


Trim ColValue once rather than every iteration through the loop.
Use a case-insensitive string compare rather than performing .ToLower() on two different strings on every loop iteration.


Result:

private string FindInT(DataTable dt, string ColName, string ColValue, string returnCol)
{
    ColValue = ColValue.Trim();
    foreach (DataRow row in dt.Rows)
    {
        if (string.Equals(
            row[ColName].ToString().Trim(),
            ColValue,
            StringComparison.InvariantCultureIgnoreCase))
        {
            return row[returnCol].ToString();
        }
    }
    return "";
}