码迷,mamicode.com
首页 > Windows程序 > 详细

C# - ref

时间:2014-10-28 17:58:56      阅读:268      评论:0      收藏:0      [点我收藏+]

标签:ref   c#   

The ref keyword causes an argument to be passed by reference, not by value. The effect of passing by reference is that any change to the parameter in the called method is reflected in the calling method. For example, if the caller passes a local variable expression or an array element access expression, and the called method replaces the object to which the ref parameter refers, then the caller’s local variable or the array element now refer to the new object.

Note: 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 byref 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.

To use a ref parameter, both the method definition and the calling method must explicitly use theref keyword. An argument that is passed to a ref parameter must be initialized before it is passed.

C# - ref

标签:ref   c#   

原文地址:http://blog.csdn.net/troubleshooter/article/details/40541239

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!