dan*_*kob -2 c# collections func
所以我有这个基于的function
返回元素collection
condition
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)