Performance of pass by value vs. pass by reference in C# .NET

后端 未结 7 1584
遇见更好的自我
遇见更好的自我 2020-12-05 18:27

I\'ve created a lightweight class with a constructor that takes around 10 parameters. The class does not change the parameter values; it just stores the values locally via

7条回答
  •  有刺的猬
    2020-12-05 19:20

    No. For reference types, you are passing a reference already, there is no need to pass the reference by reference unless you want to change what the reference points to, e.g. assign it a new object. For value types, you can pass by reference, but unless you have a performance problem, I wouldn't do this. Especially if the types in question are small (4 bytes or less), there is little or no performance gain, possibly even a penalty.

提交回复
热议问题