How to use Array.All() to check if all the elements in int array match a condition in C#

3 Answers

0 votes
using System;
using System.Linq;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] arr = { 13, 15, 33, 50, 99, 200 };

            bool b = arr.All(element => element >= 13);

            Console.WriteLine(b);
        }
    }
}


/*
run:

True

*/

 



answered Mar 1, 2017 by avibootz
0 votes
using System;
using System.Linq;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] arr = { 13, 15, 33, 50, 99, 200 };

            bool b = arr.All(element => element >= 40);

            Console.WriteLine(b);
        }
    }
}


/*
run:

False

*/

 



answered Mar 1, 2017 by avibootz
0 votes
using System;
using System.Linq;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] arr = { 13, 15, 33, 50, 99, 200 };

            bool b = arr.All(element => element < 300);

            Console.WriteLine(b);
        }
    }
}


/*
run:

True

*/

 



answered Mar 1, 2017 by avibootz
...