Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3282484
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:56:00+00:00 2026-05-17T19:56:00+00:00

I have:- IEnumerable<IEnumerable<T>> items; and I’d like to create:- IEnumerable<IEnumerable<T>> results; where the first

  • 0

I have:-

IEnumerable<IEnumerable<T>> items;

and I’d like to create:-

IEnumerable<IEnumerable<T>> results;

where the first item in “results” is an IEnumerable of the first item of each of the IEnumerables of “items”, the second item in “results” is an IEnumerable of the second item of each of “items”, etc.

The IEnumerables aren’t necessarily the same lengths. If some of the IEnumerables in items don’t have an element at a particular index, then I’d expect the matching IEnumerable in results to have fewer items in it.

For example:-

items = { "1", "2", "3", "4" } , { "a", "b", "c" };
results = { "1", "a" } , { "2", "b" }, { "3", "c" }, { "4" };

Edit: Another example (requested in comments):-

items = { "1", "2", "3", "4" } , { "a", "b", "c" }, { "p", "q", "r", "s", "t" };
results = { "1", "a", "p" } , { "2", "b", "q" }, { "3", "c", "r" }, { "4", "s" }, { "t" };

I don’t know in advance how many sequences there are, nor how many elements are in each sequence. I might have 1,000 sequences with 1,000,000 elements in each, and I might only need the first ~10, so I’d like to use the (lazy) enumeration of the source sequences if I can. In particular I don’t want to create a new data structure if I can help it.

Is there a built-in method (similar to IEnumerable.Zip) that can do this?

Is there another way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T19:56:01+00:00Added an answer on May 17, 2026 at 7:56 pm

    Now lightly tested and with working disposal.

    public static class Extensions
    {
      public static IEnumerable<IEnumerable<T>> JaggedPivot<T>(
        this IEnumerable<IEnumerable<T>> source)
      {
        List<IEnumerator<T>> originalEnumerators = source
          .Select(x => x.GetEnumerator())
          .ToList();
    
        try
        {
          List<IEnumerator<T>> enumerators = originalEnumerators
            .Where(x => x.MoveNext()).ToList();
    
          while (enumerators.Any())
          {
            List<T> result = enumerators.Select(x => x.Current).ToList();
            yield return result;
            enumerators = enumerators.Where(x => x.MoveNext()).ToList();
          }
        }
        finally
        {
          originalEnumerators.ForEach(x => x.Dispose());
        }
      } 
    }
    
    public class TestExtensions
    {
      public void Test1()
      {
        IEnumerable<IEnumerable<int>> myInts = new List<IEnumerable<int>>()
        {
          Enumerable.Range(1, 20).ToList(),
          Enumerable.Range(21, 5).ToList(),
          Enumerable.Range(26, 15).ToList()
        };
    
        foreach(IEnumerable<int> x in myInts.JaggedPivot().Take(10))
        {
          foreach(int i in x)
          {
            Console.Write("{0} ", i);
          }
          Console.WriteLine();
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an IEnumerable of an item class defined like this: public class Item
I have a IEnumerable<T> collection with Name, FullName and Address. The Address looks like
Does dot net have an interface like IEnumerable with a count property? I know
Assume we have a method like this: public IEnumerable<T> FirstMethod() { var entities =
I have an IEnumerable<string > which I would like to split into groups of
I have an IEnumerable of invoices, these invoices have line items. These line items
I have a snippet to create a 'Like' button for our news site: <iframe
I would like a Covariant collection whose items can be retrieved by index. IEnumerable
I'm a newbie when it comes to LINQ... I have an IEnumerable generic list
If I have variable of type IEnumerable<List<string>> is there a LINQ statement or lambda

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.