Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it useful to put the C# 7.2 'in' parameter modifier everywhere

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) ?

like image 700
Orace Avatar asked Jan 24 '26 12:01

Orace


1 Answers

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:

  • Using C# 7.2 in modifier for parameters with primitive types
like image 124
Heinzi Avatar answered Jan 27 '26 00:01

Heinzi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!