Table of Contents

RandomOrDefault Method

Definition

Namespace
Cuemon.Extensions.Collections.Generic
Assemblies
Cuemon.Extensions.Collections.Generic.dll
Source
src/Cuemon.Extensions.Collections.Generic/EnumerableExtensions.cs

RandomOrDefault<T>(IEnumerable<T>)

Returns a random element of a sequence of elements, or a default value if no element is found.

public static T RandomOrDefault<T>(this IEnumerable<T> source)

Parameters

source IEnumerable<T>

An IEnumerable<T> to extend.

Returns

T

default if source is empty; otherwise, a random element of source.

Type Parameters

T

The type of the elements of source.