-> 运算符(C# 参考)

-> 运算符将指针取消引用与成员访问组合在一起。

备注

以下形式的表达式

x->y

(其中 x 为 T* 类型的指针,y 为 T 的成员)等效于

(*x).y

只能在标记为不安全的代码中使用 -> 运算符。

不能重载 -> 运算符。

// 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# 参考

C# 编程指南

C# 运算符