Zip N IEnumerables together? Iterate over them simultaneously?

前端 未结 6 1575
春和景丽
春和景丽 2020-12-06 18:57

I have:-

IEnumerable> items;

and I\'d like to create:-

IEnumerable> r         


        
6条回答
  •  眼角桃花
    2020-12-06 19:13

    What about this?

            List items = new List()
            {
                new string[] { "a", "b", "c" },
                new string[] { "1", "2", "3" },
                new string[] { "x", "y" },
                new string[] { "y", "z", "w" }
            };
    
            var x = from i in Enumerable.Range(0, items.Max(a => a.Length))
                    select from z in items
                           where z.Length > i
                           select z[i];
    

提交回复
热议问题