© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•13mo ago•
30 replies
Odex

`readonly` struct, `in` modifier and defensive copies

Hi people, I just encountered the
in
in
modifier for structs.
As far as I'm concerned the
in
in
modifier can negatively affect performance if the struct I'm passing is NOT
readonly
readonly
, because it might create defensive copies - however, how can I avoid defensive copies without marking my struct
readonly
readonly
? Is there a rule of thumb when defensive copies are created?
Thanks in advance!
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
Readonly struct property vs member variable
C#CC# / help
3y ago
❔ Generally, how do you implement a readonly struct?
C#CC# / help
4y ago
difference between `struct` and `ref struct`
C#CC# / help
12mo ago