Jon Jagger
jon@jaggersoft.com
Table of Contents 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 Notes DownloadECMA-334 C# Language Specificationpreviousnextprevious at this levelnext at this level 25 Unsafe codeprevious at this levelnext at this level 25.5 Pointers in expressionsprevious at this levelnext at this level 25.5.2 Pointer member access Paragraph 11 A pointer-member-access consists of a primary-expression, followed by a "->" token, followed by an identifier. pointer-member-access : primary-expression -> identifier Paragraph 21 In a pointer member access of the form P->I, P must be an expression of a pointer type other than void*, and I must denote an accessible member of the type to which P points. Paragraph 31 A pointer member access of the form P->I is evaluated exactly as (*P).I. 2 For a description of the pointer indirection operator (*), see §25.5.1. 3 For a description of the member access operator (.), see §14.5.4. [Example: In the example
struct Point  
{  
   public int x;  
   public int y;  
   public override string ToString() {  
      return "(" + x + "," + y + ")";  
   }  
}  
using System;  
class Test  
{  
   static void Main() {  
      Point point;  
      unsafe {  
         Point* p = &point;  
         p->x = 10;  
         p->y = 20;  
         Console.WriteLine(p->ToString());  
      }  
   }  
}  
the -> operator is used to access fields and invoke a method of a struct through a pointer. Because the operation P->I is precisely equivalent to (*P).I, the Main method could equally well have been written:
using System;  
class Test  
{  
   static void Main() {  
      Point point;  
      unsafe {  
         Point* p = &point;  
         (*p).x = 10;  
         (*p).y = 20;  
         Console.WriteLine((*p).ToString());  
      }  
   }  
}  
end example]
{ JSL }
Jagger Software Ltd
Company # 4070126
VAT # 762 5213 42
Valid HTML 4.01Valid CSS