Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当方法接受 ValueType 的 out/ref 参数时,是否会发生装箱/拆箱?
对于ref关键字它已经在MSDN上提到:
ref
不要将通过引用传递的概念与引用类型的概念混淆。这两个概念并不相同。方法参数无论是值类型还是引用类型,都可以通过 ref 进行修改。通过引用传递值类型时没有装箱。
至于out关键字:
out
out关键字导致参数通过引用传递。这类似于ref关键字,只是 ref 要求在传递变量之前对其进行初始化。