Are structs 'pass-by-value'?

前端 未结 9 1359
轮回少年
轮回少年 2020-11-30 23:43

I\'ve recently tried to create a property for a Vector2 field, just to realize that it doesn\'t work as intended.

public Vector2 Position { get;         


        
9条回答
  •  半阙折子戏
    2020-12-01 00:06

    Objects are passed by reference and structs by value. But note that you have the "out" and "ref" modifiers on arguments.

    So you can pass a struct by reference like so:

    public void fooBar( ref Vector2 position )
    {
    }
    

提交回复
热议问题