How to get the last even number form int array 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, 2, 3, 4, 5, 6, 7 };

            int lastEven = arr.Last(element => element % 2 == 0);

            Console.WriteLine(lastEven);
        }
    }
}


/*
run:

6

*/

 



answered Feb 24, 2017 by avibootz

Related questions

1 answer 130 views
1 answer 177 views
1 answer 136 views
1 answer 110 views
110 views asked Sep 5, 2023 by avibootz
...