I have a method that returns a list. It takes 6 parameters (leg numbers). There is also a property that keeps track of the Number of Legs (it can have a value between 1-6). I can't seem to figure out if its possible to incorporate a loop and only add the list items depending on the Number of legs.
private List<T> ReturnListOfTypes<T>(T leg1, T leg2, T leg3,
T leg4, T leg5, T leg6)
{
List<T> legs = new List<T>();
for (int i = 0; i < NumberOfLegs; i++)
{
}
legs.Add(leg1);
legs.Add(leg2);
legs.Add(leg3);
legs.Add(leg4);
legs.Add(leg5);
legs.Add(leg6);
return legs;
}
If NumberOfLegs = 3, I only want the list to add:
legs.Add(leg1);
legs.Add(leg2);
legs.Add(leg3);
If NumberOfLegs = 1, it should only add leg 1 to the list:
legs.Add(leg1);
Right now, the list items are outside of the loop, because I can't figure out a way to only add the specified items depending on what the loop value is.