C# Passing arguments by default is ByRef instead of ByVal

后端 未结 5 1861
闹比i
闹比i 2020-12-05 07:40

I know the default is ByVal in C#. I used same variable names in many places and then I noticed passed values change and come back. I think I knew scope mechanism of C# wron

5条回答
  •  遥遥无期
    2020-12-05 08:10

    Ran across this and thought I should share what Microsoft says:

    "Do not confuse the concept of passing by reference with the concept of reference types. The two concepts are not the same. A method parameter can be modified by ref regardless of whether it is a value type or a reference type. There is no boxing of a value type when it is passed by reference."

    MSDN: ref (C# Reference)

提交回复
热议问题