void Main()
{
List<SomeContainer> someList = new List<SomeContainer>();
someList.Add(new SomeContainer { a = true, b = true, c = true });
someList.Add(new SomeContainer { a = false, b = true, c = false });
someList.Add(new SomeContainer { a = true, b = true, c = false });
someList.Add(new SomeContainer { a = true, b = false, c = false });
someList.Add(new SomeContainer { a = true, b = false, c = false });
someList.Add(new SomeContainer { a = true, b = true, c = false });
someList.Add(new SomeContainer { a = true, b = true, c = false });
var q1 = from container in someList where container.a == true select container.a;
var q2 = from container in someList where container.b == true select container.b;
var q3 = from container in someList where container.c == true select container.c;
q1.Count().Dump();
q2.Count().Dump();
q3.Count().Dump();
}
class SomeContainer
{
public Boolean a { get; set; }
public Boolean b { get; set; }
public Boolean c { get; set; }
}
是否有可能通过一个问答生成类似这样的内容:
a | b | c
6 | 5 | 1减少LINQ查询的数量
所以有可能在一个查询中做到这一点!完美解决方案 – 2011-03-24 12:53:10