Compare Two lists in C#

Hi All,

Below is the code to compare two lists and return the list that has the records that are not available another list

public List<class> compareAndReturn(List<Class> A, List<Class> B)
{
List<Class> result = new List<Class>();
foreach (var item in A)
{
if (!B.Exists(r => r.Id == item.Id))
{
result.Add(item);
}
}
return result;
}

Here list is of type Class in C#

Hope this helps : )

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s