Access members via -> : struct unsafe code « struct « C# / CSharp Tutorial






When you access a member of a structure through a pointer, you must use the arrow operator, which is ->, rather than the dot (.) operator.

using System;
using System.Globalization;

struct Point
{
  public int x;
  public int y;
  public override string ToString() 
  {
    return "(" + x + "," + y + ")";
  }
}


public class MainClass{

  static void Main(string[] args)
  {
    Console.WriteLine("Access members via ->");
    unsafe
    {
      Point point;
      Point* p = &point;
      p->x = 100;
      p->y = 200;
      Console.WriteLine(p->ToString());
    }
  }
}
Access members via ->
(100,200)








6.11.struct unsafe code
6.11.1.struct with unsafe code(pointer)
6.11.2.Access members via ->
6.11.3.Use pointer indirection and . operator