c# - Func vs. Action vs. Predicate - Stack Overflow Func is a delegate (pointer) to a method, that takes zero, one or more input parameters, and returns a value (or reference) Predicate is a special kind of Func often used for comparisons (takes a generic parameter and returns bool) Though widely used with Linq, Action and Func are concepts logically independent of Linq
c# - Delegates: Predicate vs. Action vs. Func - Stack Overflow Action, Func and Predicate all belong to the delegate family Action: Action can take n input parameters but it returns void Func: Func can take n input parameters but it will always return the result of the provided type Func<T1,T2,T3,TResult>, here T1,T2,T3 are input parameters and TResult is the output of it
Why would you use Expression lt;Func lt;T gt; gt; rather than Func lt;T gt;? Conceptually, Expression<Func<T>> is completely different from Func<T> Func<T> denotes a delegate which is pretty much a pointer to a method and Expression<Func<T>> denotes a tree data structure for a lambda expression This tree structure describes what a lambda expression does rather than doing the actual thing It basically holds data about
c# - How does func ACTUALLY work - Stack Overflow You have both Func and Action, which are in-built delegates The difference between these is that Func returns a type and Action does not You'll find Func uses heavily in the IEnumerable(T) Interface, with Linq extension methods Take a look at this example from the MSDN link provided
How can I pass in a func with a generic type parameter? public void SomeUtility(Func<T><object,T> converter) { var myType = converter<MyType>("foo"); } Edit (see also my discussion in the comments with Lawrence) : By "generic type converter" I meant I would like to pass in a converter that can convert to any strong type <T> (not object), so the next line in my method could be:
c# - Using Func delegate with Async method - Stack Overflow Cannot convert async lambda expression to delegate type 'Func<HttpResponseMesage>' An async lambda expression may return void, Task or Task<T> , none of which are convertible to 'Func<HttpResponseMesage>'