[ACCEPTED]-what is Func<TResult> in C#?-delegates

Accepted answer
Score: 11

Func<TResult> represents a method taking 0 arguments 4 and returning an object of TResult, whereas Action<T> represents 3 a method returning void. You need two different 2 delegates as you can't specify void as a type 1 argument.

Score: 1

Func<TResult> Delegate (an example can be found on the MSDN page).

Encapsulates 3 a method that has no parameters and returns 2 a value of the type specified by the TResult 1 parameter.

Score: 1

Func is like Action except it returns an object of 4 the last generic type passed in. So for 3 instance, Func<string> takes no parameters and returns 2 a string. Func<int, string>takes an int as a parameter and returns 1 a string.

Score: 1

Action is effectively equal to an encapsulation 3 of:

void Foo<T>(T arg)

Whereas Function would be equal to the 2 encapsulation of:

TResult Foo<TResult>()

If you do not understand 1 the T or TResult part, take a look at generics: https://msdn.microsoft.com/en-us/library/512aeb7t.aspx

More Related questions