List<A> aList = new List<A>()
{
new A(){ ID = 1, Phone= 123 },
new A(){ ID = 2, Phone= 222 },
new A(){ ID = 3, Phone= 333 },
new A(){ ID = 4, Phone= 123 },
};
我要取出
new A(){ ID = 1, Phone= 123 },
new A(){ ID = 4, Phone= 123 },
也就是Phone 相同的 ,用Linq 。。。该怎么做呀,虚心求教。。我已经研究了好长时间了。。。
------解决思路----------------------
from l in list
group l by l.Phone into g
where g.Count()>1
select g;
上面写错了,要改成>1
------解决思路----------------------
var result = from r in lst
group r by r.Phone into g
where g.Count() > 1
select g;
//遍历分组结果集
foreach (var item in result)
{
foreach (A u in item)
{
Console.WriteLine(u.ID);
}
}