C# pass by value/ref?

前端 未结 4 1698
借酒劲吻你
借酒劲吻你 2020-12-05 04:58

Common question but I could use an \"english\" explanation.

Is it like Java where

Cat myCat

actually is a pointer to Cat

4条回答
  •  -上瘾入骨i
    2020-12-05 05:35

    Remember that a pointer is not exactly the same as a reference, but you can just about think of it that way if you want.

    I swear I saw another SO question on this not 10 minutes ago, but I can't find the link now. In the other question I saw, they were talking about passing arguments by ref vs by value, and it came down to this:

    By default in .Net, you don't pass objects by reference. You pass references to objects by value.

    The difference is subtle but important, especially if, for example, you want to assign to your passed object in the method.

提交回复
热议问题