.net 比较特定属性上的两个常规列表

.net 比较特定属性上的两个常规列表,.net,vb.net,generics,.net-2.0,list,.net,Vb.net,Generics,.net 2.0,List,我正在使用VB.NET和.NET2.0 我有两个列表,我想比较对象中特定属性的列表,而不是整个对象,并创建一个新列表,其中包含一个列表中的对象,而不是另一个列表中的对象 myList1.Add(New Customer(1,"John","Doe") myList1.Add(New Customer(2,"Jane","Doe") myList2.Add(New Customer(1,"","") 上述示例中的结果将包含一个客户,Jane Doe,因为标识符2不在第二个列表中 如何比较.NE

我正在使用VB.NET和.NET2.0

我有两个列表,我想比较对象中特定属性的列表,而不是整个对象,并创建一个新列表,其中包含一个列表中的对象,而不是另一个列表中的对象

myList1.Add(New Customer(1,"John","Doe")
myList1.Add(New Customer(2,"Jane","Doe")

myList2.Add(New Customer(1,"","")
上述示例中的结果将包含一个客户,Jane Doe,因为标识符
2
不在第二个列表中

如何比较.NET2.0中的这两个
列表
或任何
IEnumerable
(缺少LINQ)?

这是C版本,VB即将推出

Dictionary<int, bool> idMap = new Dictionary<int, bool>();
myList2.ForEach(delegate(Customer c) { idMap[c.Id] = true; });

List<Customer> myList3 = myList1.FindAll(
    delegate(Customer c) { return !idMap.ContainsKey(c.Id); });
这是C#版本,VB即将发布

Dictionary<int, bool> idMap = new Dictionary<int, bool>();
myList2.ForEach(delegate(Customer c) { idMap[c.Id] = true; });

List<Customer> myList3 = myList1.FindAll(
    delegate(Customer c) { return !idMap.ContainsKey(c.Id); });
这在c#2.0中是可能的

List results=list1.FindAll(代表(客户)
{
返回列表2.存在(委托(客户客户2)
{
return customer.ID==customer2.ID;
});
});
这在c#2.0中是可能的

List results=list1.FindAll(代表(客户)
{
返回列表2.存在(委托(客户客户2)
{
return customer.ID==customer2.ID;
});
});

我想分享比较两个对象列表的功能:

代码:


我想分享比较两个对象列表的功能:

代码:

使用VB.NET(.NET 2.0)是否可能?使用VB.NET(.NET 2.0)是否可能?
List<Customer> results = list1.FindAll(delegate(Customer customer)
                          {
                              return list2.Exists(delegate(Customer customer2)
                                               {
                                                   return customer.ID == customer2.ID;
                                               });
                          });
Public Function CompareTwoLists(ByVal NewList As List(Of Object), ByVal OldList As List(Of Object))
            If NewList IsNot Nothing AndAlso OldList IsNot Nothing Then
                If NewList.Count <> OldList.Count Then
                    Return False
                End If
                For i As Integer = 0 To NewList.Count - 1
                    If Comparer.Equals(NewList(i), OldList(i)) = False Then
                        Return False
                    End If
                Next
            End If
            Return True
End Function
Dim NewList as new list (of string) from{"0","1","2","3"} 
Dim OldList as new list (of string) from{"0","1","2","3"} 
messagebox.show(CompareTwoLists(NewList,OldList)) 'return true 

Dim NewList as new list (of string) from{"0","1","2","4"} 
Dim OldList as new list (of string) from{"0","1","2","3"} 
messagebox.show(CompareTwoLists(NewList,OldList)) 'return false