Use Any with condition in CSharp

Description

The following code shows how to use Any with condition.

Example


using System;//from  w  ww.jav a2  s  .  com
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;

public class MainClass{
   public static void Main(){
       int[] numbers = { 2, 6, 1, 5, 10 };
       Console.WriteLine("Is there at least one odd number?");
       Console.Write(numbers.Any(e => e % 2 == 1) ? "Yes, there is" : "No, there isn't");
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    LINQ »




Operator
Select
Where
OrderBy
Group
Join
Let
LINQ