.NET Fiddle

CSharp · Console

/Program.cs

using System;
					
public class Program
{
	public static void Main()
	{
		int a = 5;
		int b = 6;
		
		_swapWontWork(a,b);
		
		Console.WriteLine("a={0}, b={1}",a,b);
		
		_swap(ref a, ref b);
		
		Console.WriteLine("a={0}, b={1}",a,b);
	}
	
	static void _swapWontWork(int a, int b)
	{
			     int tmp = a;
		 a = b;
		 b = tmp;
	}
	
	static void _swap(ref int a, ref int b)
	{
	     int tmp = a;
		 a = b;
		 b = tmp;
	}
}
;