我已经编写了以下 linq 查询,但没有得到预期的结果。例如,我的预期结果是 lst 和 list 之间的所有匹配记录以及 list 中的所有不匹配记录。
我想要以下结果
a,b,c,d,e,f
public class Com : IEqualityComparer<DuplicateData>
{
public bool Equals(DuplicateData x, DuplicateData y)
{
return x.address.Equals(y.address);
}
public int GetHashCode(DuplicateData obj)
{
return obj.address.GetHashCode();
}
}
static void Run ()
{
List<string> lst = new List<string>();
lst.Add("a");
lst.Add("b");
lst.Add("c");
lst.Add("p");
List<DuplicateData> list = new List<DuplicateData>()
{
new DuplicateData{address="a"},
new DuplicateData{address="a"},
new DuplicateData{address="a"},
new DuplicateData{address="b"},
new DuplicateData{address="b"},
new DuplicateData{address="c"},
new DuplicateData{address="d"},
new DuplicateData{address="e"},
new DuplicateData{address="f"},
};
var dup = list.Distinct(new Com());
var RightJoin = from x in dup
join y in lst
on x.address equals y
into right
from z in right
select new
{
UniqueAddress = z,
};
}