Boxing and unboxing when using out and ref parameters

前端 未结 1 857
清酒与你
清酒与你 2021-02-18 21:26

Does boxing/unboxing occur when a method accepts an out/ref parameter of a ValueType?

1条回答
  •  不思量自难忘°
    2021-02-18 21:59

    For ref Keyword Its already mentioned on MSDN that :

    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.

    As for out keyword:

    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.

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