Use unsage code to swap two integers : Unsafe Code : Language Basics C# Source Code


Custom Search

C# Source Code » Language Basics » Unsafe Code »

 

Use unsage code to swap two integers








    
 


public class TestUnsafeApp
{
    unsafe public static void Swap(int* pi, int* pj)
    {
        int tmp = *pi;
        *pi = *pj;
        *pj = tmp;
    }
   
    public static void Main(string[] args)
    {
        int i = 3;
        int j = 4;
        Console.WriteLine("BEFORE: i = {0}, j = {1}", i, j);
   
        unsafe { Swap(&i, &j); }
   
        Console.WriteLine("AFTER:  i = {0}, j = {1}", i, j);
    }
}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Language Basics
» Unsafe Code