Your version is most likely the fastest runtime option. The List<T>.FindAll you created is effective because it performs minimal checks.
However, you can use LINQ to make the code simpler and easier to maintain:
IEnumerable<Person> people = List; // Start with no filters // Add filters - just chaining as needed if (!string.IsNullOrWhitespace(name) && !string.IsNullOrWhitespace(lastname)) { people = people.Where(s => s.Name == name && s.Surname == lastname); if (!string.IsNullOrWhitespace(phone)) people = people.Where(s => s.Phone == phone); } //... Add as many as you want List<Person> newList = people.ToList(); // Evaluate at the end
This will be much more convenient and probably โfast enoughโ because filtering is usually not performed in a narrow loop.
source share