Any with false predicate

   
 

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

public class MainClass {
    public static void Main() {
        string[] presidents = {"G", "H", "a", "H", "over", "Jack"};
        bool any = presidents.Any(s => s.StartsWith("A"));
        Console.WriteLine(any);
    }
}

    


Any with string operator

   
 

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

public class MainClass {
    public static void Main() {
        string[] presidents = {"G", "H", "a", "H", "over", "Jack"};
        bool any = presidents.Any(s => s.StartsWith("Z"));
        Console.WriteLine(any);
    }
}

    


Use Quantifiers: Any

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

public class MainClass {
    public static void Main() {
        string[] words = { "bei", "rie", "rei", "field" };

        bool iAfterE = words.Any(w => w.Contains("ei"));

        Console.WriteLine("There is a word that contains in the list that contains 'ei': {0}", iAfterE);
    }
}

    


Any with condition

   
 
using System;
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");
   }
}

    


All with string length

   
 

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

public class MainClass {
    public static void Main() {
        string[] presidents = {"G", "H", "a", "H", "over", "Jack"};
        bool all = presidents.All(s => s.Length > 3);
        Console.WriteLine(all);
    }
}

    


All with Predicate to Return True

   
 

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

public class MainClass {
    public static void Main() {
        string[] presidents = {"G123456", "H", "a", "H", "over", "Jack"};
        bool all = presidents.All(s => s.Length > 5);
        Console.WriteLine(all);
    }
}