Answers for "Swap with only one line c#"

C#
0

Swap with only one line c#

using System;

class Demo {

   public static void Main(String[] args) {
      int val1 = 30;
      int val2 = 60;

      Console.WriteLine("Values before swap");
      Console.WriteLine(val1);
      Console.WriteLine(val2);

      val1 = val1 ^ val2 ^ (val2 = val1);

      Console.WriteLine("Values after swap");
      Console.WriteLine(val1);
      Console.WriteLine(val2);
   }
}
Posted by: Guest on October-13-2021

C# Answers by Framework

Browse Popular Code Answers by Language