相关疑难解决方法(0)

C#Count()扩展方法性能

如果在具有属性的Count()情况下调用LINQ 扩展方法(例如),该方法是否查找该属性并将其返回(而不是通过枚举它来计算项目)?以下测试代码似乎表明它确实:IEnumerable<T>CountList<T>Count()

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace CountSpeedTest
{
    // Output:
    // List      - CLR : 0 ms
    // Enumerate - CLR : 10 ms
    // List      - Mine: 12 ms
    // Enumerate - Mine: 12 ms
    class Program
    {
        private const int Runs = 10;
        private const int Items = 1000000;

        static void Main(string[] args)
        {
            var total = new long[] {0, 0, 0, 0};
            for (int …
Run Code Online (Sandbox Code Playgroud)

c# linq extension-methods count

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

标签 统计

c# ×1

count ×1

extension-methods ×1

linq ×1