So, here is my problem, I have this object, which is IEnumerable, and I am guaranteed that there will always be no more than 4 elements in this collection. Now, for some reason, which is not important, I would like, for some elegant way, to "force" the collection to contain 4 elements, if it is less.
I've already done some research, and the most compelling candidate is Zip, but it stops after it reaches the shortest end of the collection.
Is there a way to do this without my own extension method? To better explain yourself:
var list1 = new List<Dog> { new Dog { Name = "Puppy" } } var list2 = new List<Dog> { new Dog { Name = "Puppy1" }, new Dog { Name = "Puppy2" }, new Dog { Name = "Puppy3" }, new Dog { Name = "Puppy4" }, } var other1 = list1.ExtendToNElements(4).ToList();
Thanks in advance!
source share