tags:

views:

45

answers:

1

i'm new to linq, what i want is to do group by with having like in tqsl. my class:

class test{
public int field1;
public int field2;
public int field3;
}

now i have:

IEnumerable<test> list;

i want something like:

IEnumerable<test> q=
from p
in list
group p by p.field1
having p.field2==p.field2.Max()
select p;

Can u help me?

A: 

Just use the where-keyword, LINQ will sort it out for you.

EDIT: Some nice examples on the use of LINQ

Joachim VR
i dont need sort, i need group by
eba
I don't literally mean "sorting", it's just an expression in english. I mean LINQ will make the distinction internally, without you having to worry about it.
Joachim VR
how can i write MAX condition in WHERE?
eba
You'd have to use a where statement like this: group p by p.field1 into g where g.Key == g.Max(obj=> obj.field2)
Joachim VR
thx wrote smth like this!
eba