Declare an additional temporary variable, copy the value or reference of one of the two variables into it, and then perform the swap.
var a = 10;
var b = 20;
var temp = a;
a = b;
b = temp;
Using a tuple, you can achieve the swap in a single line.
(b, a) = (a, b)
ยฉ 2025 juniyunapapa@gmail.com.