In C# 7, it's apparently not possible to destructure to a tuple with only one item.
ValueTuple<T1>
exists, so it's not because of that.
And backwards compatibility means a Deconstruct
method with one argument must also be legal:
public void Deconstruct(out int i)
So why couldn't you write:
var (num) = foo;
Is it simply that there's no sensible use case for this?
C# deconstruction is a process of deconstruct instance of a class. It is helpful when we want to reinitialize object of a class. Make sure all the parameters of deconstructor are out type.
My guess: consider the following case:
int num;
(num) = foo;
If foo
defines a deconstructor with out int
and an implicit int cast operator, it will be ambiguous which should be invoked in this case
It is possible to have a compile error in this specific case while allowing the general case I guess, but since, as you mentioned, there is no use case and the syntax would be confusing, maybe it makes sense to not allow it at all
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With