我以前没有使用过 LINQ,但我知道它的效率有多高。
我创建了一个带有对象的列表,您可以在下面看到:
public sealed class Item
{
public long Start { private set; get; }
public long End { private set; get; }
public Item(string start, string end)
{
this.Start = Convert.ToInt64(start);
this.End = Convert.ToInt64(end);
}
}
Run Code Online (Sandbox Code Playgroud)
这将填充DataSet包含大约 200k 个项目的 s。
现在,我想在属性“开始”和“结束”之间选择最佳的单个项目。
this.ItemList.Add(new Item(100000, 100002));
this.ItemList.Add(new Item(100003, 100006));
this.ItemList.Add(new Item(100007, 100012));
this.ItemList.Add(new Item(100013, 100026));
this.ItemList.Add(new Item(100027, 100065));
Run Code Online (Sandbox Code Playgroud)
从另一个工具中,我得到了值:100009
如何new Item(100007, 100012)使用 LINQ 取回对象?有没有人有什么建议?