Hi,
I want to take the results of a where clause on a list and then take that result set and create just one new type that has all its fields constructed from aggregates of the orginal query. So given the basic example below, is there anyway to combine the 2 linq statements into one? If the orginal where has no rows then it should return null. Thanks!
class Foo
{
public int A { get; set; }
public int B { get; set; }
}
List<Foo> lst = GetFooList();
var q = (from f in lst
where f.A > 3
select f).ToList();
if (q.Count != 0)
{
var qq = new
{
MinA = q.Min(l => l.A),
MaxB = q.Max(h => h.B),
};
// now do something with qq
}
Update: For my situation, the original set has lots of items but after the where clause the result set is very small. Enumerating over the second set serveral times should not be a problem. Also I need to use first and last on the set to get a value from those records. The group by answer will work best for me. The aggreate way is very interesting and I think have another use for that. Thanks!