Why can struct change their own fields?

前端 未结 5 1385
终归单人心
终归单人心 2020-12-03 16:11

Consider the Foo struct as follows:

struct Foo
{
  public float X;
  public float Y;

  public Foo(float x, float y)
  {
    this.X = x;
    this.Y = y;
  }
         


        
5条回答
  •  鱼传尺愫
    2020-12-03 16:48

    Found my answer at the very bottom of: http://www.albahari.com/valuevsreftypes.aspx

    However, I still don't understand why the compiler allows mutable structs in that case.

提交回复
热议问题