我有一个类似的查询:LINQ的返回NULL“假”,其中clausule
var solution = (from hit2 in Hits.Where(x => x.Combination.Count == 2)
where IsPossibleHit(hit2, 2, currentSymbols)
from hit3 in Hits.Where(x => x.Combination.Count == 3)
where IsPossibleHit(hit3, 3, currentSymbols)
from hit4 in Hits.Where(x => x.Combination.Count == 4)
where IsPossibleHit(hit4, 4, currentSymbols)
from hit5 in Hits.Where(x => x.Combination.Count == 5)
where IsPossibleHit(hit5, 5, currentSymbols)
select new
{
hitsList = new List<Hit>(){
hit2,
hit3,
hit4,
hit5}
}).ToList();
我的问题是,当使群体,如果HIT2和HIT3是可能的点击,我需要新的对象被创建,但是,因为hit4返回false,整个组合被丢弃。
这怎么能实现呢?
编辑:我觉得我没搞清楚我需要什么,还是我的问题是什么:
我的问题是,当IsPossibleHit(hitN)返回false,整个组合被丢弃(通过LINQ) ,但我需要的是无论如何都创建了对象,将返回false的匹配设置为null,甚至不会将其添加到新对象的Hit列表中。
如果你不想hit4,那么为什么把它放在where子句中? – 2011-06-15 13:56:32
只有当hit4的IsPossibleHit返回true时,我才需要它。 (查询是放弃组合,而不是我) – 2011-06-15 13:58:07
然后,它正在做你想做的,hit4返回false,整个组合被丢弃。我可能会误解这里。 – 2011-06-15 13:59:25