我有以下代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TestSomethingRelatedToLINQ
{
class Person : IEqualityComparer<Person>
{
internal int personID;
internal string PersonName;
public bool Equals(Person x, Person y)
{
return x.personID == y.personID;
}
public int GetHashCode(Person obj)
{
return obj.personID.GetHashCode();
}
}
class Program
{
static void Main(string[] args)
{
List<Person> list1 = new List<Person>{
new Person{personID = 1 , PersonName = "Ali"},
new Person{personID = 2 , PersonName = "Ali1"},
new Person{personID = 3 , PersonName = "Ali2"}
};
List<Person> list2 = new List<Person>{
new Person{personID = 4 , PersonName = "Habib1"},
new Person{personID = 2 , PersonName = "Habib2"},
new Person{personID = 5 , PersonName = "Habib3"}
};
}
}
}
我需要选择 list1 中的所有元素,并且 list2 中没有 personID 的所有元素都存在于 List1 中,然后按 personID 对结果进行排序
新的输出应该像
1, Ali
2, Ali1
3, Ali2
4, Habib1
5, Habib3
任何想法如何使用它