I was going through few examples and came across below code:
(a, b) = (b, a);
It was mentioned that this can be used to swap the values of the two variables.
I tried it out as below:
int a = 5, b = 10;
Console.WriteLine(a + " " + b); // Prints --> 5 10
(b, a) = (a, b);
Console.WriteLine(a + " " + b); // Prints --> 10 5
What is this syntax? Is it something new or is this some weird trick to get the swapping result. Can it also be used with any number of variables.
Like:
(a, b, c) = (c, a, b); // a=c; b=a; c=b; or even more variables