how to find even and odd in given Array in LINQ

Suku76
Posted by Suku76 under LINQ category on | Points: 40 | Views : 477
List<int> list = new List<int>() { 20,21,36,30,31,35,89,99,12,39,19};
IEnumerable<IGrouping<int, int>> g = from l in list group l by l % 2;
foreach (var group in g)
{
Console.WriteLine(group.Key==0 ? "even numbers :" : "Odd Numbers :");
foreach (var i in group)
Console.WriteLine(i);
}
Console.ReadKey();

Comments or Responses

Login to post response