Hi,
I have a concern about declaring variable(s) inside a for/foreach/while/dowhile loop which would last for more than 1000~10000 iterations.
We won’t bother about declaring any number of variables (string[],List<t>, Dictionary<key,value>) (forgot about creating a custom type and adding to a list) and keep on instantiating it for each and every time when the loops iterates. And we don’t have (know either) any tool to point out if this was correct or wrong.
My question here is, anyone have any concern about this? Are we following the correct way of using something like this?
The reason for this post. Because I do this and I want to know whether I was following a correct way of coding.
Please let me know if any one can't understand this question.
foreach (var cItem in DataQualityMonitoringViewDataGrid.VisibleColumns.Where(lwhr => lwhr.SortDirection != SortDirection.None))
{
var statusProcessing = string.Format("Processing {0} Row", row);
var fName = cItem.FieldName.Replace(".ValueText", "").ToUpper();
if (fName == Constants.DG_COL_STATUS) continue;
fName = cItem.FieldName.Replace(".ValueText", "");
string xmlDbApiFName;
CommonUtils.ColumnCollection.TryGetValue(cItem.FieldName.ToUpper(), out xmlDbApiFName);
if (string.IsNullOrEmpty(xmlDbApiFName)) break;
var currstatusDQmCell = currentCol.Columns(fName) as DQMCell;
var currStatusVal = currstatusDQmCell.Columns("ValueText");
if (string.IsNullOrEmpty(currStatusVal.ToString()))
condition += @" not(" + xmlDbApiFName + " != '') and ";
else
condition += @" contains(" + xmlDbApiFName + ",'" + currStatusVal + "') and ";
const string conditionRed = " contains(_x0031_5010,'0')";
var forRed = CommonUtils.XmlDocument.SelectNodes("//Distinct_DQM[" + condition + conditionRed + "]");
if (forRed != null && forRed.Count >= 1)
ApplyCellColor(currentCol, CommonUtils.GetColor("0"), fName.ToUpper(), DQMFlag.red);
else
{
const string conditionAmber = " contains(_x0031_5010,'1')";
var foramberd = CommonUtils.XmlDocument.SelectNodes("//Distinct_DQM[" + condition + conditionAmber + "]");
if (foramberd != null && foramberd.Count >= 1)
ApplyCellColor(currentCol, CommonUtils.GetColor("1"), fName.ToUpper(), DQMFlag.amber);
else
{
var dQmFlag = DQMFlag.amber;
Enum.TryParse(currentCol.Status_15010.ValueText, out dQmFlag);
ApplyCellColor(currentCol, currentCol.Status_15010.Background, fName.ToUpper(), dQmFlag);
}
}
column++;
currentCol.IsHeatMapApplied = true;
}