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

后端 未结 7 1620
遇见更好的自我
遇见更好的自我 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:08

    As far as I understand you have a class with only fields and a constructor that is assigning the parameters to those fields, right?

    If that is the case I would consider using ref in the constructor bad practice. If you assign the parameter to a field in that class it is stored by value in any case. So if you dont change the value in the constructor there is no need to use it by reference.

提交回复
热议问题