-> Operator (C# Reference)

 

Updated: July 20, 2015

For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.

The -> operator combines pointer dereferencing and member access.

An expression of the form,

x->y  

(where x is a pointer of type T* and y is a member of T) is equivalent to,

(*x).y  

The -> operator can be used only in code that is marked as unsafe.

The -> operator cannot be overloaded.

    // compile with: /unsafe

    struct Point
    {
        public int x, y;
    }

    class MainClass12
    {
        unsafe static void Main()
        {
            Point pt = new Point();
            Point* pp = &pt;
            pp->x = 123;
            pp->y = 456;
            Console.WriteLine("{0} {1}", pt.x, pt.y);
        }
    }
    /*
    Output:
    123 456
    */

C# Reference
C# Programming Guide
C# Operators

Show: