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

Switch Expression Syntax with Block #2964

Closed
TonyValenti opened this issue Nov 15, 2019 · 6 comments
Closed

Switch Expression Syntax with Block #2964

TonyValenti opened this issue Nov 15, 2019 · 6 comments

Comments

@TonyValenti
Copy link

Hi All,
How do I do the following in a switch expression?

var Value = input switch {
  0 => 0,
 //How do I do this part?
 _ => {
    var r = 1;
    return r;
  }
};

Thanks so much!

@spydacarnage
Copy link

spydacarnage commented Nov 15, 2019 via email

@TonyValenti
Copy link
Author

Interesting! Based on the => syntax, I really perceived that what was on the right hand was an anonymous function which would allow block style syntax. From what I'm hearing, that is not correct though.

Am I right?

@spydacarnage
Copy link

spydacarnage commented Nov 15, 2019 via email

@HaloFour
Copy link
Contributor

There are some proposals to explore allowing multiple statements to act as an expression:

#377

@gafter
Copy link
Member

gafter commented Nov 16, 2019

Either #377 or define a local function and call it.

@YairHalberstadt
Copy link
Contributor

Closing as championed at #3037

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

5 participants