Erw*_*ers 0 c# lambda delegates
我正在阅读一些代码并看到以下内容:
Method.Find(delegate(Department depts) {
return depts.Id == _departmentId; });
Run Code Online (Sandbox Code Playgroud)
该T Find方法具有以下描述:
public T Find(Predicate<T> match);
// Summary:
// Searches for an element that matches the conditions defined by the specified
// predicate, and returns the first occurrence within the entire
// System.Collections.Generic.List<T>.
//
// Parameters:
// match:
// The System.Predicate<T> delegate that defines the conditions of the element
// to search for.
// (...)
Run Code Online (Sandbox Code Playgroud)
是否有可能重写此方法以将lambda表达式作为参数,如果是,如何?
如果要将lambda表达式传递给它,该方法已经可以接受lambda表达式作为参数.
该方法只是表明它接受委托.有几种方法可以定义委托:
Find(a => true))Find(someNamedMethod)Find((Predicate<Whatever>)Delegate.CreateDelegate(typeof(SomeClass), someMethodInfo)))