I have a List of Lists. To do some Opertations with each of those lists, i separate the Lists by a property and set a temp List with its value; The list can be sometimes empty. That is why i use this function for assignment.
EDIT: My current solution is this simple method. It should be easily adaptable.
private List<string> setList(List<string> a, int count)
{
List < string > retr;
if(a.Capacity == 0)
{
retr = new List<string>();
for(int counter = 0; counter < count; counter++)
{
retr.Add(string.empty);
}
}
else
{
retr = a;
}
return retr;
}
Is there a better way to either take a list as values or initialize a list with element count? Or should I implement my own "List" class that has this behavior?
List.Capacityis not the same asList.Count, it doesn't get trimmed when you clear the list. What's the point of this method? Why wouldn't you instantiate a new list if the previous one is also empty? Also, there is no "list of lists" in your code.