ExperimentalEnumerableTrySingleT, TCardinality(IEnumerableT, TCardinality, TCardinality, TCardinality) Method
Returns a tuple with the cardinality of the sequence and the
single element in the sequence if it contains exactly one element.
similar to
SingleTSource(IEnumerableTSource).
Namespace: MoreLinq.ExperimentalAssembly: MoreLinq (in MoreLinq.dll) Version: 4.4.0+6d97c3b1d482f98300f4446df14742b0e3fafbec
public static (TCardinality , T ) TrySingle<T, TCardinality>(
this IEnumerable<T> source,
TCardinality zero,
TCardinality one,
TCardinality many
)
<ExtensionAttribute>
Public Shared Function TrySingle(Of T, TCardinality) (
source As IEnumerable(Of T),
zero As TCardinality,
one As TCardinality,
many As TCardinality
) As ( As TCardinality, As T)
public:
[ExtensionAttribute]
generic<typename T, typename TCardinality>
static ValueTuple<TCardinality, T> TrySingle(
IEnumerable<T>^ source,
TCardinality zero,
TCardinality one,
TCardinality many
)
[<ExtensionAttribute>]
static member TrySingle :
source : IEnumerable<'T> *
zero : 'TCardinality *
one : 'TCardinality *
many : 'TCardinality -> ValueTuple<'TCardinality, 'T>
- source IEnumerableT
- The source sequence.
- zero TCardinality
-
The value that is returned in the tuple if the sequence has zero
elements.
- one TCardinality
-
The value that is returned in the tuple if the sequence has a
single element only.
- many TCardinality
-
The value that is returned in the tuple if the sequence has two or
more elements.
- T
-
The type of the elements of source.
- TCardinality
-
The type that expresses cardinality.
ValueTupleTCardinality,
T
A tuple containing the identified
TCardinality
and either the single value of
T in the sequence
or its default value.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).
This operator uses immediate execution, but never consumes more
than two elements from the sequence.