相关疑难解决方法(0)

Find()与FirstOrDefault()的性能

类似的问题:
Find()vs. Where().FirstOrDefault()

在具有单个字符串属性的简单引用类型的大序列中搜索Diana有一个有趣的结果.

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

public class Customer{
    public string Name {get;set;}
}

Stopwatch watch = new Stopwatch();        
    const string diana = "Diana";

    while (Console.ReadKey().Key != ConsoleKey.Escape)
    {
        //Armour with 1000k++ customers. Wow, should be a product with a great success! :)
        var customers = (from i in Enumerable.Range(0, 1000000)
                         select new Customer
                         {
                            Name = Guid.NewGuid().ToString()
                         }).ToList();

        customers.Insert(999000, new Customer { Name = diana }); // Putting Diana at the end :)

        //1. System.Linq.Enumerable.DefaultOrFirst() …
Run Code Online (Sandbox Code Playgroud)

.net c# linq performance

100
推荐指数
2
解决办法
6万
查看次数

标签 统计

.net ×1

c# ×1

linq ×1

performance ×1