相关疑难解决方法(0)

这两种算法之间是否存在改变IEnumerable的性能差异?

这两个问题为洗刷IEnumerable提供了类似的算法:

以下是两种方法并排:

public static IEnumerable<T> Shuffle1<T> (this IEnumerable<T> source)
{
    Random random = new Random ();
    T [] copy = source.ToArray ();

    for (int i = copy.Length - 1; i >= 0; i--) {
        int index = random.Next (i + 1);
        yield return copy [index];
        copy [index] = copy [i];
    }
}


public static IEnumerable<T> Shuffle2<T> (this IEnumerable<T> source)
{
    Random random = new Random ();
    List<T> copy = source.ToList ();

    while (copy.Count > 0) {
        int index …
Run Code Online (Sandbox Code Playgroud)

c# linq performance ienumerable

4
推荐指数
1
解决办法
1731
查看次数

标签 统计

c# ×1

ienumerable ×1

linq ×1

performance ×1