How to get intersect/minus records from record list

How to get intersect/minus records from record list

  

Hi,

I am having 2 record list, and i want to get intersect of records like,

List 1

1   record_1

2   record_2

3   record_3

4   record_4

5   record_5


List 2

2   record_2

3   record_3


Expected result is

1   record_1

4   record_4

5   record_5

Both List 1 and List 2 are comes from external web service, now to acheive this i can use loop through all the records(it will be thousands of records, not good looping i believe for performane), and is any other way to do this in better performance? or looping is the only way.


Can anyone suggest me.


Thanks,

Balu


Hi Balu,

There are a couple of ways to do that better than loops.

Use hashtable to add the first list and check the second.

Create a .net extension with this https://docs.microsoft.com/pt-br/dotnet/api/system.linq.enumerable.intersect?redirectedfrom=MSDN&view=netframework-4.7.2

I don't think is your case but If you have complex lists a possibility is to bulkinsert everything on the database and do the check on db

Regards,

Marcelo

Hello,


You can use TextDictionary extension, that comes with the platform and you only need to add the dependency to your module.


Then you will only need to use a "For loop" to insert the first list into the dictionary and another to go through the second list and have "if" to evaluate if the dictionary does/doesn't have your record and you can append it to another list.


Gabriel