In LINQ, quantifier operators are used to returning a boolean value which shows that whether some or all elements satisfies the given condition. The Standard Query Operator supports 3 different types of quantifier operators:
The Contains operator is used to check whether the given sequence or collection contains the specified element or not. It will return true if the given sequence contains the specified element, otherwise, return false. It is overloaded in two different types:
- Contains<TSource>(IEnumerable<TSource>, TSource): This method is used to check whether a sequence contains a specified element by using the default equality comparer.
- Contains<TSource>(IEnumerable<TSource>, TSource, IEqualityComparer<TSource>): This method is used to check whether a sequence contains a specified element by using a specified IEqualityComparer.
- It does not support query syntax in C# and VB.Net languages.
- It support method syntax in both C# and VB.Net languages.
- It present in both the Queryable and Enumerable class.
- It will throw ArgumentNullException if the given source is null.
- It does not return value instead of this it return true or false.
- The return type of this operator is System.Boolean.
- You can use custom class that derives IEqualityOperator with Contains to check for the object in the given collection.
Result: True Result: False
Employee Found?: False