Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
redundancer opened this issue Oct 8, 2021 · 1 comment
Open

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

redundancer opened this issue Oct 8, 2021 · 1 comment

Comments

@redundancer
Copy link

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
Copy link

silkfire commented Oct 8, 2021

You can use a combination of ToOption and Map:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants