C#C
C#3y ago
Tim

Readonly struct property vs member variable

What would make the difference between
readonly struct Values{
  float MyValue { get; }
  // .. constructor
}

and
readonly struct Values{
  readonly float MyValue;
  // .. constructor
}

I see the approach using the property lose it's value here, since the struct is already readonly (e.g. copying is useless)
Is there a 'better' method between these two? Or better said, why would anyone even use the first approach?
Was this page helpful?