If I have, for example the following List<int>s
{ 1, 2, 3, 4 } //list1
{ 2, 3, 5, 6 } //list2
...
{ 3, 4, 5 } //listN
What is the best way to retrieve the following corresponding List<int?>s?
{ 1, 2, 3, 4, null, null } //list1
{ null, 2, 3, null, 5, 6 } //list2
...
{ null, null, 3, 4, 5, null } //listN
I’m posting the solution we discussed in chat. I had an unoptimized version using Linq for all things loopy/filtering:
However, I suspect it won’t be too performant because of all the enumerator classes created, and the collections being instantiated/modified along the way.
So I took the time to optimize it into handwritten loops with an administration to keep track of active iterators instead of modifying the
iterscollection. Here it is:See http://ideone.com/FuZIDy for full live demo.
Use it like this:
It prints (for demo purposes I print the results sideways):
Note: You might like to change the interface to accept arbitrary number of lists, instead of a single sequence of sequences:
That way you could just call