8 ms·
So ignoring all the confused replies you got from people who didn't read TFA, it looks like Deconstructors allow a concrete class to participate in multiple ass
by taco_emoji 10y ago
So ignoring all the confused replies you got from people who didn't read TFA, it looks like Deconstructors allow a concrete class to participate in multiple assignment (aka deconstruction) just like a Tuple. Like with Tuple, you can deconstruct like this:
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;