Swapping of Two Values without using Third Variable

Using signs + and - for swapping of two values.

using system;
 

namespace TestConsole

{

    class Program

    {

        static void Main()

        {

            int a = 10; int b = 20;

            Console.write("After swap a = {0} and b = {1}", a, b); a = a + b - (b = a);

            Console.Write("After swap a = {0} and b = {1}", a, b);

        }

    }

}

Ebook Download
View all
Learn
View all