All Operator


The All operator checks whether all elements of a sequence satisfy a condition.


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


 








using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication4

{

  class Program

   {

    static void Main(string[] args)

    {

     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);


      Console.ReadLine();

     }

   }

}





Output:


                    

Aspnet Related Tutorials

...more

New Aspnet Resources

...more

Copyright © 2012 VisualBuilder. All rights reserved