Deconstruction with out declarations #611
Replies: 17 comments
-
With hindsight, this was a rubbish idea, so retracted 😄 |
Beta Was this translation helpful? Give feedback.
-
Oh my... |
Beta Was this translation helpful? Give feedback.
-
I suppose this is already planned as |
Beta Was this translation helpful? Give feedback.
-
I want to be able to write |
Beta Was this translation helpful? Give feedback.
-
Tagging @gafter. Neal, is this already in the bucket of work we're thinking about for the next wave of pattern matching/deconstruction? If not, could it be added. It certainly seems like deconstruction would naturally be available in these locations. |
Beta Was this translation helpful? Give feedback.
-
Would that be legal into existing variables? Bar bar;
if (dict.TryGetValue(str, out (_, bar)))
{
// use bar
} Would construction/deconstruction with void SomeMethod(ref (Foo, Bar) tuple) { ... }
Foo foo = default;
Bar bar = default;
SomeMethod(ref (foo, bar)); |
Beta Was this translation helpful? Give feedback.
-
This was something that we took up in the LDM when we were triaging and decided against doing, at least for the near future. I can't find any notes about that decision (but I did find the earlier https://github.com/dotnet/csharplang/blob/master/meetings/2016/LDM-2016-04-12-22.md where it was introduced), but I remember we definitely put it off. Also, it doesn't currently have a champion. |
Beta Was this translation helpful? Give feedback.
-
It's too bad, it seems to be a small feature that is really missing. |
Beta Was this translation helpful? Give feedback.
-
Just chiming in here to say that this has been coming up a lot for me since I've started using tuples. They're very convenient things to use as the |
Beta Was this translation helpful? Give feedback.
-
Given that
Is it worth championing this feature with the hope that a community member would implement it, even if the language/compiler team do not have time themselves? |
Beta Was this translation helpful? Give feedback.
-
To be more precise, although there are design questions around this, they are mostly along the lines of: "We know where we want to end up with this ideally. How much can we do in one go?". As such, the obvious answer is, however much gets implemented! |
Beta Was this translation helpful? Give feedback.
-
Regarding @HaloFour's example it will really be useful for wrapping dictionaries as a different view: public bool TryGetValue(string key, out Bar bar)
{
return dict.TryGetValue(key, out (_, bar))
} |
Beta Was this translation helpful? Give feedback.
-
I'm shocked this still is not implemented |
Beta Was this translation helpful? Give feedback.
-
Just to add to the information on this, the reason the LDM was uncomfortable with this feature as proposed is that C#'s |
Beta Was this translation helpful? Give feedback.
-
@gafter , this can be implemented just as a syntax sugar.
|
Beta Was this translation helpful? Give feedback.
-
@gafter , uh, I reread your comment, so in multithreading environment those deconstructed |
Beta Was this translation helpful? Give feedback.
-
Also connecting
and then
Also out deconstruction already works when you try to deconstruct inside deconstruction like |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I would like to be able to write:
It's hard to think of a good name for the tuple other than
t
, but ideally I'd just get what I want and not have to name the tuple at all.The compiler won't accept this today and I can't find existing discussion on it. Thoughts?
It would provide a nice symmetry with this:
Beta Was this translation helpful? Give feedback.
All reactions