I have an excel with 10 columns, I need to validate the values in each column of this excel separately and that is why I am looping through each column one by one.
Now the validation for each column is different.For some columns I need to compare the values in the columns with the values in certain lists.
These Lists say: List1 List2 List3...
Contain the Valid values.The values entered in the columns should be a part of these lists. So, say the first column should contain only the values that are a part of list 1.
What could be the most efficient way to do this? colcount here is 10, rowcount is 5.
for (int c = 1; c <= colcount; c++)
{
for (int r = 2; r <= rowcount; r++)
{
string celldata = usedRange.Cells[r,c].Text;
if (c == 1)
{
if (List1.Contains(celldata))
{
return true;
}
else
{
return false;
}
}
else if (c == 2)
{
if (List2.Contains(celldata))
{
return true;
}
else
{
return false;
}
}
else if (c == 3)
{
if (List3.Length <=10 && regex.IsMatch(celldata))
{
return true;
}
else
{
return false;
}
}
}
}
Can't figure out if I am making some basic mistake.
returnwill exit the entire function.What are you trying to accomplish by returning true and false?forloop smells of bad design. Once inside the inner loop you already know the value ofc, so I think this could be restructured better.