© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
3 replies
Tim

Readonly struct property vs member variable

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

and
readonly struct Values{
  readonly float MyValue;
  // .. constructor
}
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?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

readonly struct and readonly struct instance members (optimization?)
C#CC# / help
4y ago
✅ Return readonly property
C#CC# / help
2y ago
❔ Struct vs Class
C#CC# / help
3y ago
`readonly` struct, `in` modifier and defensive copies
C#CC# / help
13mo ago