dan*_*kob -2 c# collections func
所以我有这个基于的function返回元素collectioncondition
public static T Search<T>(IEnumerable<T> source, Func<T, bool> filter)
{
return source.FirstOrDefault(filter);
}
Run Code Online (Sandbox Code Playgroud)
而且我想将其转换为返回elements我的collection那个形式的所有形式condition.
所以不要将函数签名更改为 public static IEnumerable<T> Search<T>(IEnumerable<T> source, Func<T, bool> filter)
我需要在我的功能中改变什么?
用Where而不是FirstOrDefault
public static IEnumerable<T> Search<T>(IEnumerable<T> source, Func<T, bool> filter)
{
return source.Where(filter);
}
Run Code Online (Sandbox Code Playgroud)