Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 重复生成序列号_C#_Linq_Sequence - Fatal编程技术网

C# 重复生成序列号

C# 重复生成序列号,c#,linq,sequence,C#,Linq,Sequence,我有以下代码: var result = AllSequences(1, 10, 3); public static IEnumerable<List<int>> AllSequences(int start, int end, int size) { if (size == 0) return Enumerable.Repeat<List<int>>(new List<int>(), 1); ret

我有以下代码:

var result = AllSequences(1, 10, 3);

public static IEnumerable<List<int>> AllSequences(int start, int end, int size)
{
    if (size == 0)
        return Enumerable.Repeat<List<int>>(new List<int>(), 1);

    return from i in Enumerable.Range(start, end - size - start + 2)
           from seq in AllSequences(i, end, size - 1)
           select new List<int> { i }.Concat(seq).ToList();
}
但在开始这个序列之前,希望你是这样的:

2,1,1
2,1,2
2,1,3
2,1,4
.....

生成序列时遇到的问题是,我使用LINQ在这个循环中获得性能

我对你的问题有点困惑,但是如果你想让序列从1到10贯穿每个数字,对于所有排列,请尝试类似的方法

我在这里并不提倡使用LINQ,只是尝试对代码进行尽可能少的更改

    public static IEnumerable<List<int>> AllSequences(int start, int end, int size)
    {
        if (size == 0)
            return Enumerable.Repeat<List<int>>(new List<int>(), 1);

        return from i in Enumerable.Range(start, end)
               from seq in AllSequences(start, end, size - 1)
               select new List<int> { i }.Concat(seq).ToList();
    }
,您如何知道LINQ将获得性能?
    public static IEnumerable<List<int>> AllSequences(int start, int end, int size)
    {
        if (size == 0)
            return Enumerable.Repeat<List<int>>(new List<int>(), 1);

        return from i in Enumerable.Range(start, end)
               from seq in AllSequences(start, end, size - 1)
               select new List<int> { i }.Concat(seq).ToList();
    }
1, 1, 1
1, 1, 2
... etc
1, 1, 10
1, 2, 1
1, 2, 2
... etc
1, 10, 8
1, 10, 9
1, 10, 10
2, 1, 1
2, 1, 2 
.... etc
10, 10, 10