Even and Odd Split



Even and Odd

This is a C# demonstration that uses LINQ to seperate 8 integers into 2 groups, even and odd.

Here's the code!

                           using System;
                            using System.Linq;

                            namespace EvenAndOdd
                            {
                                class Program
                                {
                                    static void Main(string[] args)
                                    {
                                        int input;
                                        int[] linqArray = new int[8];
                                        for (int x = 0; x < linqArray.Length; ++x)
                                        {
                                            Console.Write("Please enter an integer: ");
                                            linqArray[x] = Convert.ToInt32(Console.ReadLine());
                                        }

                                        var even =
                                            from x in linqArray
                                            where x % 2 == 0
                                            select x;

                                        var odd =
                                            from x in linqArray
                                            where x % 2 == 1
                                            select x;

                                        Console.Write("Odd > ");
                                        foreach (var x in even)
                                        {
                                            Console.Write("{0} ", x);
                                        }
                                        Console.Write("\nEven > ");
                                        foreach (var x in odd)
                                        {
                                            Console.Write("{0} ", x);
                                        }
                                        Console.Write("\n");
                                        Console.ReadLine();
                                    }
                                }
                            }