How to get all the odd numbers until the first even number from array of ints in C#

1 Answer

0 votes
using System;
using System.Linq;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] arr = { 1, 3, 5, 6, 7, 8, 9 };

            var match = arr.TakeWhile(item => item % 2 != 0);

            foreach (int n in match)
            {
                Console.WriteLine(n);
            }
        }
    }
}

/*
run:

1
3
5

*/

 



answered Jan 22, 2017 by avibootz
edited Jan 22, 2017 by avibootz

Related questions

...