Yes I want tell you few things related to generic delegates;
Fun<TResult>()
Fun<T1,TResult>()
Fun<T1,T2,TResult>()
Fun<T1,T2,T3,TResult>()
All these all are generic delegates and these return types also delegate type.so maximum the return delegate are written by the complier.as per our T type && as passing no’f parameters. This is greate.
Why because we don’t need to write any delegates for each lamda expression.
The only thing is we have to write a good lamda expression.
Some of basic delegates we seen with simple lamda expression now some complex type of delegate as a parameter we discuss now.
Fun<TResult>,Fun<int,TResult> we seen our example now below
Ex:
Func<bool, int, string>
Func<bool, int, string>
Func<bool, int, string> func2 = (b, x) =>
string.Format("string = {0} and {1}", b, x);
Console.WriteLine(func2.Invoke(true,10));
Then
Func<int, int, bool>
int j1 =Convert.ToInt32(Console.ReadLine());
int j2 = Convert.ToInt32(Console.ReadLine());
Func<int, int, bool> fun3 = (j4, j8) => j1 == j2;
Console.WriteLine(fun3.Invoke(j1, j2));
both j1 and j2 are equl then fun3 returns ---ture other with false
Func<int, int,int, bool>
int j1 =Convert.ToInt32(Console.ReadLine());
int j2 = Convert.ToInt32(Console.ReadLine());
int j3 = Convert.ToInt32(Console.ReadLine());
Func<int, int, int, bool> fun4 = (j10, j11, j12) => j3 == j1 + j2;
Console.WriteLine(fun4.Invoke(14, 15, 16));
both j1 and j2 added value equl to j3.
menas 1,2,3----true j1=1 j2=2 then j3=3 so true
these are good way to understand these parametrized delegates.
Note: Wherever we use generic delegate[lamda expression] there one anamous type will be created by complier implictly.
Note: a best way to know about these delegates and how annomous type use Refleactor tool.
Note: Wherever we use generic delegate[lamda expression] there one anamous type will be created by complier implictly.
Note: a best way to know about these delegates and how annomous type use Refleactor tool.
No comments:
Post a Comment