Accessing Structure Members with a Pointer : unsafe « unsafe « C# / CSharp Tutorial






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);
    }
}








36.1.unsafe
36.1.1.Unsafe Code
36.1.2.Compile unsafe code
36.1.3.Using unsafe and fixed
36.1.4.Mark method as unsafe to pointers
36.1.5.Accessing Structure Members with a Pointer
36.1.6.Unsafe Methods
36.1.7.Using the unsafe keyword.
36.1.8.unsafe block