Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

-> Operator (C# Reference)

Updated: July 2008

The -> operator combines pointer dereferencing and member access.

An expression of the form,


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


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);
123 456




July 2008

Changed "unmanaged code" to "code that is marked unsafe."

Content bug fix.

Community Additions

© 2015 Microsoft