Skip to content

M_CodeJam_Collections_EnumerableExtensions_FirstOrDefault__1_1

Andrew Koryavchenko edited this page Jul 4, 2017 · 9 revisions

EnumerableExtensions.FirstOrDefault(T) Method (IEnumerable(T), T, Func(T, Boolean))

Returns the first element of the sequence that satisfies a condition or a specified defaultValue if no such element is found.

Namespace: CodeJam.Collections
Assembly: CodeJam (in CodeJam.dll) Version: 1.1.0.0 (1.1.0.0)

Syntax

C#

public static T FirstOrDefault<T>(
	this IEnumerable<T> source,
	T defaultValue,
	Func<T, bool> predicate
)

VB

<ExtensionAttribute>
Public Shared Function FirstOrDefault(Of T) ( 
	source As IEnumerable(Of T),
	defaultValue As T,
	predicate As Func(Of T, Boolean)
) As T

F#

[<ExtensionAttribute>]
static member FirstOrDefault : 
        source : IEnumerable<'T> * 
        defaultValue : 'T * 
        predicate : Func<'T, bool> -> 'T 

Parameters

 

source
Type: System.Collections.Generic.IEnumerable(T)
An IEnumerable(T) to return an element from.
defaultValue
Type: T
Default value.
predicate
Type: System.Func(T, Boolean)
A function to test each element for a condition.

Type Parameters

 

T
The type of the elements of source.

Return Value

Type: T
default(T) if source is empty or if no element passes the test specified by predicate; otherwise, the first element in source that passes the test specified by predicate.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerable(T). When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

See Also

Reference

EnumerableExtensions Class
FirstOrDefault Overload
CodeJam.Collections Namespace

Clone this wiki locally