c# - LINQ compares the two lists and removes them

I have two lists. I want to remove any items from LIST1 that are NOT present in LIST2.

So for example:

        var list1 = new List<DownloadTask>();
        list1.Add(new DownloadTask{ OperationID = 1, MachineID = 1 });
        list1.Add(new DownloadTask{ OperationID = 2, MachineID = 1 });
        list1.Add(new DownloadTask{ OperationID = 3, MachineID = 1 });
        list1.Add(new DownloadTask{ OperationID = 3, MachineID = 2 });

        var list2 = new List<DownloadTask>();
        list2.Add(new DownloadTask{ OperationID = 1, MachineID = 1 });
        list2.Add(new DownloadTask{ OperationID = 3, MachineID = 2 });

After run list1 should contain only items: with combination operationId = 1, machineId = 1 AND OperationId = 3, MachineId =2.

This question and all comments follow the "Attribution Required."

All Answers

Answers Loading...
Leave a Reply
You must be logged in to post a answer.
About the author