gpt4 book ai didi

c# - 使用 out 和 ref 参数时的装箱和拆箱

转载 作者:可可西里 更新时间:2023-11-01 02:59:11 29 4
gpt4 key购买 nike

当方法接受 ValueType 的 out/ref 参数时是否会发生装箱/拆箱?

最佳答案

对于 ref 关键字它已经在 MSDN 上提到了那:

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.

关于out关键字:

The out keyword causes arguments to be passed by reference. This is like the ref keyword, except that ref requires that the variable be initialized before it is passed.

关于c# - 使用 out 和 ref 参数时的装箱和拆箱,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5103147/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com