【发布时间】:2012-07-31 14:26:02
【问题描述】:
public class Filter
{
public List<int> A { get; set; }
public DateTime Start { get; set; }
public DateTime End { get; set; }
}
var f1 = new Filter(){A = new List<int>() {1}}
var f2 = new Filter(){A = new List<int>() {1 , 4, 2}, Start = DateTime.Now, End = DateTime.AddHour(2)}
var dict = new Dictionary<Filter, string>()
dict.Add(new Filter(){A = new List<int>() {1}}, "asdf");
dict.Add(new Filter(){A = new List<int>() {4}}, "qwerty");
dict.Add(new Filter(){A = new List<int>() {3}}, "qwertyasd");
我需要得到:
f1 项目优先
f2 第一个和第二个项目。
如何构造linq查询?
当A 为int 时,很简单
dict.Where(k =>
k.Key.A.Equals(filter.A)
&& k.Key.Start.CompareTo(filter.Start) > 0
&& k.Key.End.CompareTo(filter.End) < 0
)
但是当它是 List<int> 时,它对我来说更复杂。
【问题讨论】:
标签: c# linq dictionary compare predicates