相关疑难解决方法(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万
查看次数

在通用列表中搜索对象

是否可以通过通用列表中的某个属性搜索对象?

Public Class Customer

    Private _id As Integer

    Private _name As String

    Public Property ID() As Integer
        Get
            Return _id
        End Get
        Set
            _id = value
        End Set
    End Property

    Public Property Name() As String
        Get
            Return _name
        End Get
        Set
            _name = value
        End Set
    End Property

    Public Sub New(id As Integer, name As String)
        _id = id
        _name = name
    End Sub

End Class
Run Code Online (Sandbox Code Playgroud)

然后加载和搜索

Dim list as new list(Of Customer)

list.Add(New Customer(1,"A")

list.Add(New Customer(2,"B")
Run Code Online (Sandbox Code Playgroud)

如何返回id = 1的客户对象?这与泛型中的"谓词"有关吗? …

vb.net generics

14
推荐指数
2
解决办法
5万
查看次数

标签 统计

.net ×1

c# ×1

generics ×1

linq ×1

performance ×1

vb.net ×1