Find even and odd numbers of a list of number
Even and Odd Numbers from the list.
using System; using System.Collections.Generic; using System.Linq; public class Program { public static void Main() { Console.WriteLine("Find even and odd numbers of a list of number:"); List<int> numberArray = new List<int> { 2, 4, 6, 1, 8, 7 }; List<int> evenNumberList = numberArray.Where(n => n % 2 == 0).Select(n => n).ToList(); List<int> oddNumberList = numberArray.Where(n => n % 2 != 0).Select(n => n).ToList(); Console.WriteLine("\nFind even numbers of a list of number"); evenNumberList.ForEach(i => Console.Write("{0}\t", i)); Console.WriteLine("\n\nFind odd numbers of a list of number"); oddNumberList.ForEach(i => Console.Write("{0}\t", i)); } }DEMO
Find even and odd numbers of a list of number
Reviewed by Bhaumik Patel
on
8:15 AM
Rating: