Since C# 7.2, the in
parameter modifier allow the passing of parameters by reference as read-only.
As I understand it, this modifier allow to pass structs by reference and ensure that the data will not be modified. It is useful for performance purposes when it's needed to pass big struct.
But, is it useful to use it for smaller struct size (like int
, bool
) ?
No, it's not useful to (blindly) put the in
parameter modifier everywhere, because the compiler might create defensive copies.
A concrete example can be found in the following question: