C# Program to Swap two Numbers


-

-

Example:

Copied
using System;

public class SwapNumbers  
{  
    public static void Main(string[] args)  
    {  
        int  num1=10, num2=20, swap;            
        Console.WriteLine("Before swap A: "+num1+" B: "+num2);    
        
        swap = num1;
		num1 = num2;
		num2 = swap;
		
        Console.Write("After swap A: "+num1+" B: "+num2);
        Console.ReadLine();
    }  
}

Output:

Before swap A: 10 B: 20
After swap A: 20 B: 10