Swapping values in c#

In previous versions of c# to swap values between two variables, you would have to use an additional paramter (unless it is an integer where you can do some simple manipulation)


string a = "a";
string b = "b";

//swap
string c = a;
a = b;
b = c;

With the latest c# version you can do it with tuples:


(a, b) = (b, a)

Post a Comment

Previous Post Next Post