I have some code that loops over a number and populates a list using other lists. I think I can refactor it somehow to make it look nicer but not sure the best way to do it.
Here is the code:
for (int i = 0; i < loopCount; i++)
{
switch (NoOfRows)
{
case 1:
if (InputList1.Count > i)
ExpectedValues.Add(InputList1[i]);
break;
case 2:
if (InputList1.Count > i)
ExpectedValues.Add(InputList1[i]);
if (InputList2.Count > i)
ExpectedValues.Add(InputList2[i]);
break;
case 3:
if (InputList1.Count > i)
ExpectedValues.Add(InputList1[i]);
if (InputList2.Count > i)
ExpectedValues.Add(InputList2[i]);
if (InputList3.Count > i)
ExpectedValues.Add(InputList3[i]);
break;
case 4:
if (InputList1.Count > i)
ExpectedValues.Add(InputList1[i]);
if (InputList2.Count > i)
ExpectedValues.Add(InputList2[i]);
if (InputList3.Count > i)
ExpectedValues.Add(InputList3[i]);
if (InputList4.Count > i)
ExpectedValues.Add(InputList4[i]);
break;
case 5:
if (InputList1.Count > i)
ExpectedValues.Add(InputList1[i]);
if (InputList2.Count > i)
ExpectedValues.Add(InputList2[i]);
if (InputList3.Count > i)
ExpectedValues.Add(InputList3[i]);
if (InputList4.Count > i)
ExpectedValues.Add(InputList4[i]);
if (InputList5.Count > i)
ExpectedValues.Add(InputList5[i]);
break;
case 6:
if (InputList1.Count > i)
ExpectedValues.Add(InputList1[i]);
if (InputList2.Count > i)
ExpectedValues.Add(InputList2[i]);
if (InputList3.Count > i)
ExpectedValues.Add(InputList3[i]);
if (InputList4.Count > i)
ExpectedValues.Add(InputList4[i]);
if (InputList5.Count > i)
ExpectedValues.Add(InputList5[i]);
if (InputList6.Count > i)
ExpectedValues.Add(InputList6[i]);
break;
case 7:
if (InputList1.Count > i)
ExpectedValues.Add(InputList1[i]);
if (InputList2.Count > i)
ExpectedValues.Add(InputList2[i]);
if (InputList3.Count > i)
ExpectedValues.Add(InputList3[i]);
if (InputList4.Count > i)
ExpectedValues.Add(InputList4[i]);
if (InputList5.Count > i)
ExpectedValues.Add(InputList5[i]);
if (InputList6.Count > i)
ExpectedValues.Add(InputList6[i]);
if (InputList7.Count > i)
ExpectedValues.Add(InputList7[i]);
break;
case 8:
if (InputList1.Count > i)
ExpectedValues.Add(InputList1[i]);
if (InputList2.Count > i)
ExpectedValues.Add(InputList2[i]);
if (InputList3.Count > i)
ExpectedValues.Add(InputList3[i]);
if (InputList4.Count > i)
ExpectedValues.Add(InputList4[i]);
if (InputList5.Count > i)
ExpectedValues.Add(InputList5[i]);
if (InputList6.Count > i)
ExpectedValues.Add(InputList6[i]);
if (InputList7.Count > i)
ExpectedValues.Add(InputList7[i]);
if (InputList8.Count > i)
ExpectedValues.Add(InputList8[i]);
break;
case 9:
if (InputList1.Count > i)
ExpectedValues.Add(InputList1[i]);
if (InputList2.Count > i)
ExpectedValues.Add(InputList2[i]);
if (InputList3.Count > i)
ExpectedValues.Add(InputList3[i]);
if (InputList4.Count > i)
ExpectedValues.Add(InputList4[i]);
if (InputList5.Count > i)
ExpectedValues.Add(InputList5[i]);
if (InputList6.Count > i)
ExpectedValues.Add(InputList6[i]);
if (InputList7.Count > i)
ExpectedValues.Add(InputList7[i]);
if (InputList8.Count > i)
ExpectedValues.Add(InputList8[i]);
if (InputList9.Count > i)
ExpectedValues.Add(InputList9[i]);
break;
case 10:
if (InputList1.Count > i)
ExpectedValues.Add(InputList1[i]);
if (InputList2.Count > i)
ExpectedValues.Add(InputList2[i]);
if (InputList3.Count > i)
ExpectedValues.Add(InputList3[i]);
if (InputList4.Count > i)
ExpectedValues.Add(InputList4[i]);
if (InputList5.Count > i)
ExpectedValues.Add(InputList5[i]);
if (InputList6.Count > i)
ExpectedValues.Add(InputList6[i]);
if (InputList7.Count > i)
ExpectedValues.Add(InputList7[i]);
if (InputList8.Count > i)
ExpectedValues.Add(InputList8[i]);
if (InputList9.Count > i)
ExpectedValues.Add(InputList9[i]);
if (InputList10.Count > i)
ExpectedValues.Add(InputList10[i]);
break;
}
}
InputList1..10
defined? \$\endgroup\$