怎么对linq查询后的结果二次查询
答案:1 悬赏:0 手机版
解决时间 2021-11-26 20:11
- 提问者网友:做自己de王妃
- 2021-11-25 19:29
怎么对linq查询后的结果二次查询
最佳答案
- 五星知识达人网友:迷人又混蛋
- 2021-11-25 19:44
public class d
{
public int a, b, x, y;
}
public class myEqual : IEqualityComparer
{
public myEqual() {
}
public bool Equals(d x, d y)
{
if (x == null || y == null) return false;
return x.x == y.x && x.y == y.y;
}
public int GetHashCode(d obj)
{
return obj.GetHashCode();
}
}
static void Main(string[] args)
{
List list = new List();
d g = new d();
g.a=1; g.b=2; g.x=11; g.y=12;
list.Add(g);
d j=new d();
j.a = 3; j.b = 4; j.x = 11; j.y = 12;
list.Add(g);
var a = list.Distinct(new myEqual());
Console.ReadKey();重写e类的Equals和GetHashCode,然后用Distinct
pst=query.Distinct().ToList();
也可以用for循环一个一个比较
{
public int a, b, x, y;
}
public class myEqual : IEqualityComparer
{
public myEqual() {
}
public bool Equals(d x, d y)
{
if (x == null || y == null) return false;
return x.x == y.x && x.y == y.y;
}
public int GetHashCode(d obj)
{
return obj.GetHashCode();
}
}
static void Main(string[] args)
{
List
d g = new d();
g.a=1; g.b=2; g.x=11; g.y=12;
list.Add(g);
d j=new d();
j.a = 3; j.b = 4; j.x = 11; j.y = 12;
list.Add(g);
var a = list.Distinct(new myEqual());
Console.ReadKey();重写e类的Equals和GetHashCode,然后用Distinct
pst=query.Distinct().ToList();
也可以用for循环一个一个比较
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯