相关疑难解决方法(0)

从IEnumerable转换为List

我想转换IEnumerable<Contact>List<Contact>.我怎样才能做到这一点?

c# ienumerable list

249
推荐指数
5
解决办法
34万
查看次数

列表的独特组合

绝对的心灵空白.那是其中的一天.但我一直在寻找一种解决方案,以获得一定长度的项目列表的独特组合.例如,给定一个列表[a,b,c]和长度为2,它将返回[a,b] [a,c] [b,c]但不返回[b,a] [c,a] [c ,b]的

为此,我发现了许多代码,但似乎没有一个代码.以下代码似乎最合适,我一直在尝试根据我的需要改变它:

// Returns an enumeration of enumerators, one for each permutation
// of the input.
public static IEnumerable<IEnumerable<T>> Permute<T>(IEnumerable<T> list, int count)
{
    if (count == 0)
    {
        yield return new T[0];
    }
    else
    {
        int startingElementIndex = 0;
        foreach (T startingElement in list)
        {
            IEnumerable<T> remainingItems = AllExcept(list, startingElementIndex);

            foreach (IEnumerable<T> permutationOfRemainder in Permute(remainingItems, count - 1))
            {
                yield return Concat<T>(
                    new T[] { startingElement },
                    permutationOfRemainder);
            }
            startingElementIndex += 1;
        }
    } …
Run Code Online (Sandbox Code Playgroud)

c# algorithm

9
推荐指数
2
解决办法
6582
查看次数

标签 统计

c# ×2

algorithm ×1

ienumerable ×1

list ×1