Notice in the 'CustomerViewModel' the region code is a mixture of upper and lower case text. This could be an issue, so to solve it when making the comparison we make all text lowercase.

The line of code that does all the work is: customerViewModels.RemoveAll(u => salesRepViewModel.Count(f => u.RegionCode.ToLower().Contains(f.RegionCode.ToLower())) == 0);

What the line of code above is doing is comparing the salesRepViewModel against the customerViewModel and removing all the region codes that have no match.

The results can be seen in the image below.

How to compare two lists in c#

How to compare two lists in c#

The example above shows how to compare two lists in a website application, once done, you would then display the results on the frontend and do whatever needs to be done.

I hope you found this short example helpful, if you did, please leave a comment below.

Leave a comment

*
*