ExperimentalEnumerableTrySingleT, TCardinality, TResult Method (IEnumerableT, TCardinality, TCardinality, TCardinality, FuncTCardinality, T, TResult) |
Returns a result projected from the the cardinality of the sequence
and the single element in the sequence if it contains exactly one
element.
Namespace:
MoreLinq.Experimental
Assembly:
MoreLinq (in MoreLinq.dll) Version: 3.3.1+b77df70598ab84c28cd43dcf74594024b6d575e1
Syntax public static TResult TrySingle<T, TCardinality, TResult>(
this IEnumerable<T> source,
TCardinality zero,
TCardinality one,
TCardinality many,
Func<TCardinality, T, TResult> resultSelector
)
<ExtensionAttribute>
Public Shared Function TrySingle(Of T, TCardinality, TResult) (
source As IEnumerable(Of T),
zero As TCardinality,
one As TCardinality,
many As TCardinality,
resultSelector As Func(Of TCardinality, T, TResult)
) As TResult
public:
[ExtensionAttribute]
generic<typename T, typename TCardinality, typename TResult>
static TResult TrySingle(
IEnumerable<T>^ source,
TCardinality zero,
TCardinality one,
TCardinality many,
Func<TCardinality, T, TResult>^ resultSelector
)
[<ExtensionAttribute>]
static member TrySingle :
source : IEnumerable<'T> *
zero : 'TCardinality *
one : 'TCardinality *
many : 'TCardinality *
resultSelector : Func<'TCardinality, 'T, 'TResult> -> 'TResult
Parameters
- source
- Type: System.Collections.GenericIEnumerableT
The source sequence. - zero
- Type: TCardinality
The value that is passed as the first argument to
resultSelector if the sequence has zero
elements. - one
- Type: TCardinality
The value that is passed as the first argument to
resultSelector if the sequence has a
single element only. - many
- Type: TCardinality
The value that is passed as the first argument to
resultSelector if the sequence has two or
more elements. - resultSelector
- Type: SystemFuncTCardinality, T, TResult
A function that receives the cardinality and, if the
sequence has just one element, the value of that element as
argument and projects a resulting value of type
TResult.
Type Parameters
- T
-
The type of the elements of source.
- TCardinality
-
The type that expresses cardinality.
- TResult
-
The type of the result value returned by the
resultSelector function.
Return Value
Type:
TResult
The value returned by
resultSelector.
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).
Remarks
This operator uses immediate execution, but never consumes more
than two elements from the sequence.
See Also