Now I am going to show you how to swap two numbers in Single statement and without using third variable.
First Method:
int x = 10;
int y = 20;
y = (x + y) - (x = y);
Console.WriteLine("X = " + x + "; Y = " + y);Output:
X = 20 ; Y = 10Second Method:
int x = 10;
int y = 20;
y = (x * y) / (x = y);
Console.WriteLine("X = " + x + "; Y = " + y);Output:
X = 20 ; Y = 10