Enumerator that yields a list of elements

44 Views Asked by At

I want to create an enumerator which will iterate over multiple lists elements one-by-one returning a list of them. For example let's say we have 3 lists, the enumerator will first yield the elements at index 0 then elements at index one and so on..

So far I have the code below but it does not work and returns only the first element. How can I achieve this ? Is this even possible ?

private class Merger : IEnumerable
{
    private readonly List<List<string>> paths;

    private readonly int maxPathLength;

    public Merger(List<List<string>> paths)
    {
        this.paths = paths;

        maxPathLength = paths.Max(x => x.Count);
    }

    public IEnumerator GetEnumerator()
    {
        for (int i = 0; i < maxPathLength; i++)
        {
            yield return paths.Select(x => x[i]);
        }
    }

}
0

There are 0 best solutions below