uses All to determine whether an array contains only odd numbers. : All « LINQ « C# / C Sharp






uses All to determine whether an array contains only odd numbers.

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass {
    public static void Main() {
        int[] numbers = { 1, 11, 3, 19, 41, 65, 19 };

        bool onlyOdd = numbers.All(n => n % 2 == 1);

        Console.WriteLine("The list contains only odd numbers: {0}", onlyOdd);
    }
}

 








Related examples in the same category

1.All with condition
2.All with Predicate to Return True
3.All with string length