 | EnumerableExtensionMethodsRandomItemOrDefaultT Method (IEnumerableT, T) |
Returns a random item from the specified sequence or the specified default value if
the sequence is null or empty.
Namespace: Slash.Collections.ExtensionsAssembly: Slash.Collections (in Slash.Collections.dll) Version: 1.0.6018.40177
Syntaxpublic static T RandomItemOrDefault<T>(
this IEnumerable<T> sequence,
T defaultValue
)
<ExtensionAttribute>
Public Shared Function RandomItemOrDefault(Of T) (
sequence As IEnumerable(Of T),
defaultValue As T
) As T
public:
[ExtensionAttribute]
generic<typename T>
static T RandomItemOrDefault(
IEnumerable<T>^ sequence,
T defaultValue
)
[<ExtensionAttribute>]
static member RandomItemOrDefault :
sequence : IEnumerable<'T> *
defaultValue : 'T -> 'T
Parameters
- sequence
- Type: System.Collections.GenericIEnumerableT
Sequence to get item from. - defaultValue
- Type: T
Default value to use if the sequence is null or empty.
Type Parameters
- T
- Type of sequence items.
Return Value
Type:
TTime-dependent random item.
Usage Note
In Visual Basic and C#, you can call this method as an instance method on any object of type
IEnumerableT. 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