相关疑难解决方法(0)

如何"压缩"或"旋转"可变数量的列表?

如果我有一个包含任意数量列表的列表,如下所示:

var myList = new List<List<string>>()
{
    new List<string>() { "a", "b", "c", "d" },
    new List<string>() { "1", "2", "3", "4" },
    new List<string>() { "w", "x", "y", "z" },
    // ...etc...
};
Run Code Online (Sandbox Code Playgroud)

...有没有办法以某种方式将列表"压缩"或"旋转"成这样的东西?

{ 
    { "a", "1", "w", ... },
    { "b", "2", "x", ... },
    { "c", "3", "y", ... },
    { "d", "4", "z", ... }
}
Run Code Online (Sandbox Code Playgroud)

显而易见的解决方案是做这样的事情:

public static IEnumerable<IEnumerable<T>> Rotate<T>(this IEnumerable<IEnumerable<T>> list)
{
    for (int i = 0; i < list.Min(x => x.Count()); i++) …
Run Code Online (Sandbox Code Playgroud)

c# linq algorithm

13
推荐指数
3
解决办法
1145
查看次数

标签 统计

algorithm ×1

c# ×1

linq ×1