//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);
Saturday, 26 April 2014
Most Occurred Number in Integer Array using Linq using C#
String[] _numbers = { "2", "1", "3", "2", "4", "6", "2", "1", "4", "6", "6", "4", "8", "1", "3", "8" };
var _query2 = from n in _numbers
group n by n into g
select new
{
number = g.Key,
count = g.Count()
};
var _MaxCount = _query2.Max(a => a.count);
var mostOccurednumber = _query2
.Where(g => g.count == _MaxCount)
.Select(g => g.number);
Friday, 25 April 2014
Merging three array and take top 5 numbers using LINQ in C#
int[] _inputs1 = { 11,12, 13, 14, 15, 16, 17, 18, 169 };
int[] _inputs2 = { 11, 22, 33, 24, 25, 56, 67, 88, 99 };
int[] _inputs3 = { 1, 2, 3, 4, 5, 6, 7, 68, 98 };
Int32[] Concatenate=Input1.Concat(Input2).Concat(Input3).OrderByDescending(a=>a)
.Take(5).ToArray();
foreach(int a in Concatenate)
{
Console.writeline(a);
}
//output {168,99,98,88,68}