Saturday, 26 April 2014

Using Predicate and Func in linq using c#

//Creation of Predicate

Predicate<String> checkGreterthen5= x=> x.Length>5;

List<String> oLst=new List<string>();

oLst.Add("sa");

oLst.Add("saurabh");

String str = oLst.Find(checkGreterthen5);

Console.WriteLine(str);//Saurabh

//Creation of Func

delegate Double CalcAreaPointer(int r);

CalcAreaPointer _obj= r => 3.14 * r*r;

Double Area=_obj(5);

Func<double,double,double> _obj2=(r,e)=> 3.14 *r*e;

//Action<>

Double Area2 = _obj2(5,2);
Share:

0 Comments:

Post a Comment