Boxing and unboxing when using out and ref parameters

风格不统一 提交于 2019-12-05 10:33:10

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/5103147/boxing-and-unboxing-when-using-out-and-ref-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!