AsEnumerable
Convert the Option<T>
to an IEnumerable<T>
of length 0 or 1.
Parameters
Returns
Option<T> option
IEnumerable<T>
Usage
Returns an IEnumerable<T>
with a single element when the option value IsSome
. Otherwise returns an empty collection.
When option IsSome
Option<int> optionValue = 42;
IEnumerable<int> result = optionValue.AsEnumerable();
//result = { 42 }
When option IsNone
Option<int> optionValue = Option<int>.None();
IEnumerable<int> result = optionValue.AsEnumerable();
//result = { }
Last updated
Was this helpful?