Optional icon indicating copy to clipboard operation
Optional copied to clipboard

How can I convert an int? to Option.Some<uint>?

Open redundancer opened this issue 2 years ago • 1 comments

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.
}

redundancer avatar Oct 08 '21 10:10 redundancer

You can use a combination of ToOption and Map:

int? value = 0;
var x = value.ToOption("Value is null").Map(v => (uint)v);

silkfire avatar Oct 08 '21 16:10 silkfire