The System.Linq Any method is a LINQ extension method that is used to determine if there are any elements in a sequence that satisfy a specified condition. It is part of the System.Linq namespace in C# and is defined as:
public static bool Any (this IEnumerable source, Func predicate);
The method takes in a source sequence and a predicate function that is used to determine the condition for each element in the sequence. It returns true if any elements in the sequence satisfy the condition, otherwise, it returns false.
Example 1: Determine if a sequence contains any even numbers
In this example, we use the Any method to determine if the numbers sequence contains any even numbers. We pass in a lambda expression that checks if the remainder of dividing the number by 2 is zero, indicating that it is even. The method returns true because the sequence does contain an even number (8).
In this example, we use the Any method to check if the word "hello" contains any vowels. We pass in a lambda expression that checks if the character is a vowel by checking if it is contained in the string "aeiou". The method returns true because the word contains a vowel.
Package Library: The Any method is part of the System.Linq namespace which is included in the .NET Framework Class Library. The library provides a set of standard query operators that allow developers to perform different types of operations on sequences, such as filtering, sorting, and grouping.
C# (CSharp) System.Linq.Any - 17 examples found. These are the top rated real world C# (CSharp) examples of System.Linq.Any extracted from open source projects. You can rate examples to help us improve the quality of examples.