Quantifiers (LINQ)
Posted by Rajinder
Last Updated: July 22, 2012

Any

This sample uses Any to determine if any of the words in the array contain the substring 'ei'.

public void Linq() 
{ 
    string[] words = { "believe""relief""receipt""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); 
}

All

public void Linq() 
{  
    int[] numbers = { 111319416519 }; 
  
    bool onlyOdd = numbers.All(n => n % 2 == 1); 
  
    Console.WriteLine("The list contains only odd numbers: {0}", onlyOdd); 
}
Related Content