Click here to Skip to main content
15,920,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey guys I have two list objects that I am trying to compare. I think the best way to do is use Linq. Ok my 2 lists are List(Of PermissionObj) so basicaly I am trying to return a list of the items that are not common to both lists.

Dim _listOfAllPermissionGroups As List(Of PermissionGroupObj)
Dim _listOfUnSelectedGroups As List(Of PermissionGroupObj)

  For Each objMember As PermissionGroupObj In _listOfAllPermissionGroups
                    For Each objUserPermissions As PermissionGroupObj In _listOfUserPermissionGroups
                        If objMember.PermissionGroupId = objUserPermissions.PermissionGroupId Then
                            Exit For
                        End If

I have used a Foreach loop but for whatever reason the matched object doesn't get removed.

Thanks guys.
Updated 12-Sep-12 1:13am
Joan M 12-Sep-12 7:03am    
Could you show us a little bit of code? with that information we can't imageine what has happened...
frostcox 12-Sep-12 7:13am    
Sorry about that.

1 solution

Share this answer
frostcox 12-Sep-12 7:24am    
Hi I tried this approach but I get an IEqualityComparer exception.
Kuthuparakkal 12-Sep-12 7:26am    
Why dont you read it fully:
If you want to compare sequences of objects of some custom data type, you have to implement the IEqualityComparer(Of T) generic interface in your class. The following code example shows how to implement this interface in a custom data type and provide GetHashCode and Equals methods.

An example already there..
frostcox 12-Sep-12 7:42am    
Ok only problem I am having is that the PermissionGroupObj is an autogenerated class that I don't really want to go messing with in case it has a knock on affect.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900