-
Notifications
You must be signed in to change notification settings - Fork 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
Question: Use of discard in deconstruction syntax #3229
Comments
It's explained by the two rules in your link:
What this means is that using System;
public class C
{
static void Main() => Console.WriteLine(new C().M());
public int M()
{
var _ = 3;
var a = 3;
(a, _) = this;
return _; // returns 2
}
public void Deconstruct(out int first, out int second) => (first, second) = (1,2);
} |
It was decided that for new features that didn't require keeping compatibility that There's some convo about it here: |
oh, I didn't think to check old Roslyn issues. Thanks! |
Given the following code sample:
In each method, the deconstruction has two elements, the first of which is always named.
In
M
, I could see this being interpreted as either a variable named_
, or as a discard.In N, I would expect
var _
to declare a variable named_
.In O, I would expect the discard to be used.
However, in all three cases, this is a discard and not a variable declaration.
What's the reason behind
var _
in a deconstruction being a discard instead of a variable, and completely overruling the idea ofvar
declaring a variable?The only commentary I can find on this is a very early LDM, and nothing in the current spec.
The text was updated successfully, but these errors were encountered: