I just used Action<T>()
and it's sibling Func<T>()
today and this disturbs my mind now:
Func<T>
is commented like this in the official docs:
Encapsulates a method that has no parameters and returns a value of the type specified by the TResult parameter.
Since even the comment mentions that is is a method (in C# there is nominally no such thing as functions, AFAIK), why the designers of C# did not just call that construct
Meth<T>
or Method<T>
?
Is it probably because of the odd sound of "Meth"? But what about method, which would be very clear?
I regard "method" as a sort of implementation detail here - whereas the mathematical concept of a function is common. (How often have you heard of delegates being described as "function pointers"?)
Note that the word "function" appears even within C# - both anonymous methods and lambda expressions are "anonymous functions".
You use Func<>
when you want a function - something that returns a value, possibly given some inputs. You don't really care whether or not it's backed by a method; it's just something you can call.
I'd say that the documentation for Func<>
is somewhat lacking here, rather than the choice of name. (Then there's the type system which prevents Func<void>
being valid, which would make things a lot simpler in numerous situations - but that's a different matter.)
See more on this question at Stackoverflow