Listnumbers = new List () { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; List evenNumbers = numbers.FindAll(n => n % 2 == 0); // evenNumbers contains 2, 4, 6, 8, 10
ListThis example creates a list of words and then uses the FindAll method to create a new list with only the words that are longer than 5 characters. The List FindAll method is part of the System.Collections.Generic namespace.words = new List () { "hello", "world", "goodbye", "csharp", "nunit" }; List longWords = words.FindAll(w => w.Length > 5); // longWords contains "goodbye" and "csharp"