WebJul 17, 2013 · 3 Answers Sorted by: 4 You need the Except method: var yourResult = col1.Except (col2); If both of your collections aren't the same type, then you're going to have to do a more expensive O (nm) search: var selectedTwo = col2.Select (x => x.ID).ToHashSet (); var yourResult = col1.Where (n => !selectedTwo.Contains (n.ID)); WebMar 16, 2024 · var differences = new HashSet (songs); differences.SymmetricExceptWith (attributes.Select (a => a.name)); if (differences.Any ()) { // The lists differ. } Share Improve this answer Follow answered Oct 1, 2013 at 15:05 Andrew Stephens 9,189 5 75 145 Add a comment 5 This is the way to find all the songs which aren't included in attributes names:
How do i get the difference in two lists in C#? - Stack Overflow
WebSep 24, 2008 · In C# 2.0 you'd write: result = mObjList.Find (delegate (int x) { return x.ID == magicNumber; }); 3.0 knows lambdas: result = mObjList.Find (x => x.ID == magicNumber); Share Improve this answer Follow answered Aug 23, 2008 at 0:41 Konrad Rudolph 523k 130 930 1207 Add a comment 4 Using a Lambda expression: WebApr 28, 2015 · 9. Sort both lists with an efficient sorting algorithm (or ensure that the lists are "pre-sorted" by whoever/whatever created them). Then, if the first name in both lists is the same you've found a match, otherwise discard whichever name is "earlier"; and do that until one of the lists are empty. ed scoda plumbing heating reviews
c# - Find items from a list which exist in another list - Stack Overflow
WebFeb 18, 2024 · I need to get the matching items in mylist1 and mylist2. The match should happen only on Property1 and Property2. Property3 in the mylist2 can be ignored during comparison. Currently I use var matchingCodes = mylist1.Where (l1 => mylist2.Any (l2 => (l2.Property1 == l1.Property1 && l2.Property2==l1.Property2))).ToList (); which works … WebJun 29, 2011 · 4. You can do this by counting occurrences of all items in all lists - those items whose occurrence count is equal to the number of lists, are common to all lists: static List FindCommon (IEnumerable> lists) { Dictionary map = new Dictionary (); int listCount = 0; // number of lists foreach (IEnumerable list in ... WebAug 30, 2024 · List.FindAll (Predicate) Method is used to get all the elements that match the conditions defined by the specified predicate. Properties of List: It is different from the arrays. A list can be resized dynamically but arrays cannot. List class can accept null as a valid value for reference types and it also allows duplicate elements. constipated facial expressions