Hooked on LINQ

Hooked on LINQ - Developers' Wiki
for .NET Language Integrated Query

Companion book for this site
LINQ to Objects Using C# 4.0:
Using and Extending LINQ to Objects and Parallel LINQ (PLINQ)
Quick Search

Advanced Search »
{TOC}
Namespace:System.Linq
Assembly:System.Core.dll
Extends:IEnumerable<T>

Back to Standard Query Operator Index


Edit

Introduction

The Contains operator checks whether a sequence contains a given element.

Edit

Method Signatures

public static bool Contains<TSource>(
    this IEnumerable<TSource> source, 
    TSource value)
 
//New in January CTP
public static bool Contains<TSource>(
    this IEnumerable<TSource> source, 
    TSource value, 
    IEqualityComparer<TSource> comparer)



Edit

Exceptions

Throws an ArgumentNullException if source is null.

Edit

Pseudocode

If source is null, throw ArgumentNullException.
If comparer is null, make it EqualityComparer<TSource>.Default;
Iterate the source sequence
- if the element == value return true
return false if end of sequence and no match found.


Edit

Code Samples

If you would like to comment on this page, click on the Discuss button located on the top-right of each page. Feel free to edit any mistakes or omissions you find. If you have an objection or find in-appropriate content then contact the administrator. This website is not affiliated with Microsoft®, all content and opinions are those of the specific author and some advice, solutions and article may contain unintentional errors - please use care. Other websites by this author: Focused Objective, Geek Speak Decoded.