nlkl / Optional

A robust option type for C#
MIT License
903 stars 73 forks source link

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

Open redundancer opened 3 years ago

redundancer commented 3 years ago
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.
}
silkfire commented 3 years ago

You can use a combination of ToOption and Map:

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