using System;
using System.Globalization;
public class MainClass{
unsafe public static void UnsafeSwap(int* i, int* j)
{
int temp = *i;
*i = *j;
*j = temp;
}
static void Main(string[] args)
{
int i = 10, j = 20;
Console.WriteLine("Unsafe swap");
Console.WriteLine("Values before unsafe swap: i = {0}, j = {1}", i, j);
unsafe{ UnsafeSwap(&i, &j);}
Console.WriteLine("Values after unsafe swap: i = {0}, j = {1}", i, j);
}
}
Unsafe swap
Values before unsafe swap: i = 10, j = 20
Values after unsafe swap: i = 20, j = 10