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