Object passed as parameter to another class, by value or reference?

前端 未结 7 1693
闹比i
闹比i 2021-02-18 21:12

In C#, I know that by default, any parameters passed into a function would be by copy, that\'s, within the function, there is a local copy of the parameter. But, what about when

相关标签:
7条回答
  • 2021-02-18 22:10

    Assuming someTestObj is a class and not a struct, the object is passed by reference, which means that both obj and someTestObj refer to the same object. E.g. changing name in one will change it in the other. However, unlike if you passed it using the ref keyword, setting obj = somethingElse will not change someTestObj.

    0 讨论(0)
提交回复
热议问题