var (ret, err) = Foo();
if (err != null) {
...
}EDIT: I don't know C#, so syntax is definitely not right.
But yes you can write a deconstructor for anything you like so it can participate in deconstructing assignment. And yes it can have side effects. And that would be VERY BAD.
So instead of having to declare that Foo returns a FooReturn, it can be declared as (say)
public (int ret, string err) Foo() { return (5, "something"); }EDIT: Looks like there's confusion... Yes, you can deconstruct a Tuple like this, but C# 7 also introduces a specific Deconstructor pattern in which ANY class can be deconstructed as though it were a Tuple.
var pix = (int R = 255, int G = 255, int B = 255);
var (r1, g1, b1) = pix;
Except what if you're also working with 3D location data? E.g.: var pos = (int X = 100, int Y = 100, int Z = 100);
var (x1, y1, z1) = pos;
Both pos and pix have the same underlying type of Tuple<int,int,int>, which could lead to confusion. Better to have concrete Pixel and Position classes. You can then give those classes a Deconstruct method and then use them the same way: var pix = new Pixel(255, 255, 255);
var (r1, g1, b1) = pix;
var pos = new Position(100, 100, 100);
var (x, y, z) = pos; someMap = {1, 2}
{foo, bar} = someMap
foo # 1
bar # 2The other new features seem like very welcome additions but the deconstructor seems a bit contrived and a rare use-case which does not directly solve an existing problem (also makes it easy to confuse desctructor/deconstructor for newbies).