using System.Collections.Generic;
public static void Main()
var cats = new List<Cat> { new Cat("Fluffy"), new Cat("Meowista"), new Cat("Scratchy") };
var (fluffy, scratchy) = cats.FindFirsts(
x => x.Name == "Scratchy");
Console.WriteLine($"{fluffy} {scratchy}");
public static class FindExtensions
public static T[] FindFirsts<T>(this IEnumerable<T> collection, params Func<T, bool>[] conditions)
if (conditions.Length == 0)
var unmatchedConditions = conditions.Length;
var lookupWork = conditions
foreach (var item in collection)
for (var i = 0; i < lookupWork.Length; i++)
if (!lookupWork[i].found && lookupWork[i].cond(item))
lookupWork[i].found = true;
lookupWork[i].value = item;
if (unmatchedConditions <= 0)
return lookupWork.Select(x => x.value).ToArray();
public static class IEnumerableExt
public static void Deconstruct<T>(this IEnumerable<T> seq, out T first, out T second)
first = seq.FirstOrDefault();
second = seq.Skip(1).FirstOrDefault();
public string Name { get; set; }
public override string ToString() => Name;