Listnumbers = new List (){1, 2, 3, 4, 5, 6}; List evenNumbers = numbers.FindAll(num => num % 2 == 0); // Output: [2, 4, 6]
ListThe above code creates a list of 5 strings and then uses the FindAll method to extract a new list that contains only the strings whose length is greater than 4 from the original list. In both examples, we are using the FindAll method of the List class to extract a new list that satisfies a predicate condition. This method is a part of the System.Collections.Generic package library in C#.names = new List (){"John", "Mary", "Jake", "Sam", "Alexis"}; List longNames = names.FindAll(name => name.Length > 4); // Output: ["Mary", "Alexis"]