Export (0) Print
Expand All
3 out of 4 rated this helpful - Rate this topic

-> Operator (C# Reference)

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 unmanaged code.

The -> operator cannot be overloaded.

// cs_operator_dereferencing.cs
// compile with: /unsafe
using System;
struct Point
{
    public int x, y; 
}

class MainClass
{
    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
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.