At the moment I have some code like below which based on a NoOfRows properties returns whether all data has been entered into list(s):
switch (NoOfRows)
{
case 1:
return InputList1.Any();
case 2:
return InputList1.Any() && InputList2.Any();
case 3:
return InputList1.Any() && InputList2.Any() && InputList3.Any();
case 4:
return InputList1.Any() && InputList2.Any() && InputList3.Any() && InputList4.Any();
case 5:
return InputList1.Any() && InputList2.Any() && InputList3.Any() && InputList4.Any() && InputList5.Any();
case 6:
return InputList1.Any() && InputList2.Any() && InputList3.Any() && InputList4.Any() && InputList5.Any() && InputList6.Any();
case 7:
return InputList1.Any() && InputList2.Any() && InputList3.Any() && InputList4.Any() && InputList5.Any() && InputList6.Any() && InputList7.Any();
case 8:
return InputList1.Any() && InputList2.Any() && InputList3.Any() && InputList4.Any() && InputList5.Any() && InputList6.Any() && InputList7.Any() && InputList8.Any();
case 9:
return InputList1.Any() && InputList2.Any() && InputList3.Any() && InputList4.Any() && InputList5.Any() && InputList6.Any() && InputList7.Any() && InputList8.Any() && InputList9.Any();
case 10:
return InputList1.Any() && InputList2.Any() && InputList3.Any() && InputList4.Any() && InputList5.Any() && InputList6.Any() && InputList7.Any() && InputList8.Any() && InputList9.Any() && InputList10.Any();
default:
return false;
}
I’m thinking it might be better to refactor this code and have an List<List<int>> or a Dictionary<int,List<int>> but how would I do the above to return whether each list in the collection has something in it?
List<List<int>> values = new List<List<int>>(){InputList1, InputList2 ... InputList10};
var lists = values.Take(NoOfRows);
lists.. //check each item and return value of Any for each one
having nested lists can work well. you might want to look into the use of selectmany
but I think the code you want is something like: