-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Proposal: If / while with multiple statements condition #13364
Comments
There's an issue about "statement expressions" somewhere around. |
This would be the "semi-colon expressions" that were proposed on CodePlex for C# 6.0 but were finally cut. Here's a mention: C# Design Notes for Dec 16, 2013 Those expressions would have extended to anywhere in the language: bool b = (var p = GetPoint(); p.X += 10; p.Length > 20); However considering the variable scoping of if ((var p = GetPoint(); p.X += 10; p.Length > 20)) {
...
}
// p is still in scope here |
Here it is, Sequence Expressions: #6182 |
Is that in reference to the scope statement? |
I don't see why sequence expressions would preclude type switch. The last statement in the sequence can be any expression, including a |
That could be "fixed" by changing the spec to allow the
Then both of the following would work: bool b = (var p1 = GetPoint(); p1.X += 10; p1.Length > 20);
if (var p2 = GetPoint(); p2.X += 10; p2.Length > 20) {
...
} |
@HaloFour
which is incorrect. And that double braces. |
I don't see why not? A type-switch is just a Boolean expression that also assigns a variable. You can use it as follows: bool b = p is Point3d p3d; Of course if (x == y || p is Point3d p3d) {
// oops, p3d not definitely assigned here
} |
Add ability to put multiple statements into condition for if and while.
Example:
Last statement (required) is expression that provide bool value.
Benefits:
The text was updated successfully, but these errors were encountered: