Accessing Structure Members with a Pointer : Unsafe Code : Language Basics C# Source Code


Custom Search

C# Source Code » Language Basics » Unsafe Code »

 

Accessing Structure Members with a Pointer








    

using System;
   
public struct Point2D {
    public int X;
    public int Y;
}
   
public class MyClass {
    public unsafe static void Main() {
        Point2D MyPoint;
        Point2D * PointerToMyPoint;
   
        MyPoint = new Point2D();
        PointerToMyPoint = &MyPoint;
        PointerToMyPoint->X = 100;
        PointerToMyPoint->Y = 200;
        Console.WriteLine("({0}, {1})", PointerToMyPoint->X, PointerToMyPoint->Y);
    }
}
           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Language Basics
» Unsafe Code