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的更多相关文章

  1. .NET 基础一步步一幕幕[out、ref、params]

    out.ref.params out: 如果你在一个方法中,返回多个相同类型的值的时候,可以考虑返回一个数组. 但是,如果返回多个不同类型的值的时候,返回数组就不行了,那么这个时候, 我们可以考虑使用 ...

  2. out和ref详解

    要想充分理解C# out和ref,必须先明确如下两个概念(对值类型与引用类型掌握比较好的,可以跳过"一.明确两个基本概念") 一.明确两个基本概念 值类型: 定义:通过值的方式来传 ...

  3. c#编程基础之ref、out参数

    引例: 先看这个源码,函数传递后由于传递的是副本所以真正的值并没有改变. 源码如下: using System; using System.Collections.Generic; using Sys ...

  4. C#中out和ref之间的区别【转】

    首先:两者都是按地址传递的,使用后都将改变原来参数的数值. 其次:ref可以把参数的数值传递进函数,但是out是要把参数清空,就是说你无法把一个数值从out传递进去的,out进去后,参数的数值为空,所 ...

  5. 通过一个实例重新认识引用类型,值类型,数组,堆栈,ref

    昨天在写代码时候遇到了一个问题,百思不得其解,感觉颠覆了自己对C#基础知识的认知,因为具体的情境涉及公司代码不便放出,我在这里举个例子,先上整个测试所有的代码,然后一一讲解我的思考过程: using ...

  6. 图解C#的值类型,引用类型,栈,堆,ref,out

    C# 的类型系统可分为两种类型,一是值类型,一是引用类型,这个每个C#程序员都了解.还有托管堆,栈,ref,out等等概念也是每个C#程序员都会接触到的概念,也是C#程序员面试经常考到的知识,随便搜搜 ...

  7. 异步方法不能使用ref和out的解决方法

    异常处理汇总-后端系列:http://www.cnblogs.com/dunitian/p/4523006.html 应用场景==>后端现在都是用异步方法,那么分页是必不可少的,于是就有了这个问 ...

  8. [C#]浅析ref、out参数

    转载:http://www.cnblogs.com/vd630/p/4601919.html#top 按引用传递的参数算是C#与很多其他语言相比的一大特色,想要深入理解这一概念应该说不是一件容易的事, ...

  9. C#基础-out与ref字段

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...

  10. C# out ref 重载

    今天看极客学院wiki时候看到了out,ref的介绍,之前对这个知识点没有深刻认识,所以就写了个小测试看了下,瞬间明白了. using System; using System.Collections ...

随机推荐

  1. js实现无限级树形导航列表

  2. android动画效果演示

    第一种:TranslateAnimation  动画效果演示: public void move(View view) { // 传统动画效果 TranslateAnimation animation ...

  3. POJ 1562(L - 暴力求解、DFS)

    油田问题(L - 暴力求解.DFS) Description The GeoSurvComp geologic survey company is responsible for detecting ...

  4. ibatis3.0调用Oracle的存储过程

    直接上源码 一,oracle储存过程. create or replace procedure proc_get_th(i_hth in varchar2,o_ret out sys_refcurso ...

  5. ubuntu12.04中如何设定中文输入法

    安装 ibus 终端输入:sudo apt-get install ibus ibus-clutter ibus-gtk ibus-gtk3 ibus-qt4 启动 ibus 终端输入 :  im-s ...

  6. mvc导航配置(View页面)

    @using Seyoit.Website.Config@using Seyoit.Website.Config.Navigation@{ var action = ViewContext.Route ...

  7. Java学习笔记:内部类/匿名内部类的全面介绍

    编写java程序时,一般一个类(或者接口)都是放在一个独立的java文件中,并且类名同文件名(如果类是public的,类名必须与文件名一致:非public得,无强制要求).如果想把多个java类放在一 ...

  8. word2vec 中的数学原理具体解释(五)基于 Negative Sampling 的模型

      word2vec 是 Google 于 2013 年开源推出的一个用于获取 word vector 的工具包,它简单.高效,因此引起了非常多人的关注. 因为 word2vec 的作者 Tomas ...

  9. 更新整理本人全部博文中提供的代码与工具(Java,2014.09)

    为了更方便地管理博文中涉及的各种代码与工具资源,如今把这些资源迁移到 GitHub 中,有兴趣者可前往下载. Java 1.<高效 Java Web 应用开发框架 JessMA v3.4.1 正 ...

  10. BZOJ 2743: [HEOI2012]采花( 离线 + BIT )

    处理出每个数下一个出现的位置, 然后按左端点排序回答询问.处理当前数去除的影响 ------------------------------------------------------------ ...