Optional
Optional copied to clipboard
How can I convert an int? to Option.Some<uint>?
private static void Main(string[] args){
var number = MyMethod1();
// How to use number in method 2?
}
int? MyMethod1(){
return 1;
}
void MyMethod2(Option<uint> aNumber){
// Do Something.
}
You can use a combination of ToOption
and Map
:
int? value = 0;
var x = value.ToOption("Value is null").Map(v => (uint)v);