Is there any other way to optimize the below code? I feel the below code is huge for the operations it performs.
if ((currentElement == null ||
(firstGridRow["Low"].ToString() == string.Empty ||
firstGridRow["High"].ToString() == string.Empty ||
firstGridRow["Mean"].ToString() == string.Empty ||
firstGridRow["StdDev"].ToString() == string.Empty)))
{
continue;
}
if (newRow.Length != 0)
{
AddColorList(currentElement, opid, currentLow, "Low", newRow, listCollectionLow);
AddColorList(currentElement, opid, currentHigh, "High", newRow, listCollectionHigh);
AddColorList(currentElement, opid, currentMean, "Mean", newRow, listCollectionMean);
AddColorList(currentElement, opid, currentStdDev, "StdDev", newRow, listCollectionStdDev);
}
You can use LINQ, like this:
private static readonly string[] AllKeys = new[] {"Low", "High", "Mean", "StdDev"};
if (currentElement == null || ALlKeys.Any(k => gridRow[k].ToString() == string.Empty)) {
...
}
if (newRow.Length != 0) {
foreach (var key in AllKeys) {
AddColorList(currentElement, opid, currentLow, key, newRow, listCollectionLow);
}
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments