【发布时间】:2016-05-27 20:17:05
【问题描述】:
我以前没有使用过 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);
}
}
这将填充DataSets,其中包含大约 20 万个项目。
现在,我想在属性“开始”和“结束”之间选择最佳单项。
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));
从另一个工具,我得到了值:100009
如何使用 LINQ 取回对象 new Item(100007, 100012)?有人有什么建议吗?
【问题讨论】:
-
如果给定的值适合两个项目,因为两者的差异相等怎么办?特别是当提供的值恰好在一个结束和下一个间隔开始之间时会发生什么?
-
不清楚你的标准是什么 - 你想找到所有开始和结束都在两个任意值之间的对象吗?
-
定义最佳。你的问题不清楚。