So Func
is a delegate?
Yes, it's defined as follows:
public delegate TResult Func<in T, out TResult>(T arg)
It's described as:
Encapsulates a method that has one parameter and returns a value of the type specified by the
TResult
parameter.
Read Func Delegate for more.
Then what is that delegate we have defined again in the code example?
That's the anonymous method we create to assign it to the Func
-typed variable. You could use named method or lambda expression as well, as long as the input and return types match the Func
generic parameters.
We define a variable from a Func that is like a delegate and then assign it again to another delegate?
No, we create a variable typed as Func<string, int>
and then create a delegate matching that type and assign it to the variable.
Additional sources from MSDN: