Func
and Anynonymos method using Func
1.
An Func is a type of delegate
just like action except func returns value and action not.
2.
Encapsulates methods that has a single/multiple parameter and
return a value.
3.
Internally it is deligate and
defined as below
Here is the actual formal definition of the Func<T,
TResult>, they are defined separately
public
delegate TResult Func<in T, out TResult>( T arg)
T=Input
Parameter
TResult
=Output Parameter
4.
It may take 0 parameter to 16 parameters as input and 1 parameter
as outpout
5. You can use the lambda expression in the action as
shown below exapmle
6.
You use Anynonymos method using Func as below
Definition
|
Func<string,
string> func1 = (x) => string.Format("string
= {0}", x);
|
In
Arguments
|
String
|
Out
Arguments
|
String
|
Call
|
func1("Ajay")
|
Returns
/ o/p
|
String = Ajay
|
Internally
Defined
|
public delegate
TResult Func<in
T, out TResult>(T arg);
|
|
|
Definition
|
Func<string,int , string> func1 = (x,y) => string.Format("string
= {0} & int = ", x,y);
|
In
Arguments
|
String, int
|
Out
Arguments
|
String
|
Call
|
Console.WriteLine(func1("Ajay",1 ));
|
Internally
Defined
|
public delegate
void Action<in T1, in T2>(T1
arg1, T2 arg2);
|
|
|
No comments:
Post a Comment