Demonstrate pointer comparison : Pointer Unsafe : Language Basics C# Source Code


Custom Search

C# Source Code » Language Basics » Pointer Unsafe »

 

Demonstrate pointer comparison









    

/*
C#: The Complete Reference 
by Herbert Schildt 

Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/


// Demonstrate pointer comparison. 
 
using System; 
 
public class PtrCompDemo { 
  unsafe public static void Main() { 
 
    int[] nums = new int[11]; 
    int x; 
 
    // find the middle 
    fixed (int* start = &nums[0]) {  
      fixed(int* end = &nums[nums.Length-1]) {  
        for(x=0; start+x <= end-x; x++) ; 
      } 
    } 
    Console.WriteLine("Middle element is " + x); 
  } 
}


           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Language Basics
» Pointer Unsafe