Table of contents
TOC
Collapse the table of content
Expand the table of content

List.contains<'T> Function (F#)

liboz|Last Updated: 8/18/2017
|
1 Contributor

Evaluates to true if the given element is in the input list.

Namespace/Module Path: Microsoft.FSharp.Collections.List

Assembly: FSharp.Core (in FSharp.Core.dll)

Syntax

// Signature:
List.contains : 'T -> 'T list -> bool

// Usage:
List.contains element source

Parameters

element Type: 'T

The element to find.

source Type: 'Tlist

The input list.

Exceptions

ExceptionCondition
ArgumentNullExceptionThrown when the input list is null.

Return Value

Evaluates to true if the given element is in the input list. Otherwise, it will return false.

Remarks

This function is named Contains in compiled assemblies. If you are accessing the function from a language other than F#, or through reflection, use this name.

Example

The following code shows how to use List.contains.

let list1 = [ 1 .. 10 ]
let list2 = List.empty

//The following line prints true
printfn "%A" (List.contains 5 list1)

//The following line prints false
printfn "%A" (List.contains 5 list2)

Output

true
false

Platforms

Windows 8, Windows 7, Windows Server 2012, Windows Server 2008 R2

Version Information

F# Core Library Versions

Supported in: 4.0, Portable

See Also

Collections.List Module (F#)

Microsoft.FSharp.Collections Namespace (F#)

© 2018 Microsoft