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. ViewPager+View实现Tab

    注:源码来自慕课网. 使用ViewPager+View实现Tab底部导航: 主要思想:顶部top.xml,中间ViewPager,底部线性布局Tab导航. top.xml具体实现: <?xml ...

  2. linux命令sysctl使用

    以前没有注意过这个命令,直到有次在单位安装greenplum的时候,在没有配置系统参数的情况下,出现了设备空间不足的报错信息. 当然,安装的不是我的本机,而是公用的服务器,编辑修改系统参数后,仍然出现 ...

  3. ASP.NET MVC 以Stream 下载文件

     1.0以Stream 下载文件 nl.fileid = Int32.Parse(id); //服务器上对应的id Stream stream = Lawsuit.DownLoad(nl);//服务器 ...

  4. Dispatcher & Redirect

    首先理解一下二者的含义:Dispatcher请求转发,直接把客户端的请求在服务器处理以后跳转到下一个页面或者是处理类.此时的地址栏上的URL是不会变化的. Redirect是重定向.客户端的请求到达服 ...

  5. QT5.6所开放的7个新模块(图表,虚拟键盘,性能分析,静态分析,测试正好,2D渲染)

    The modules newly available to open source users are: Qt Charts Qt Data Visualization Qt Virtual Key ...

  6. nginx使用小记

    中文wiki社区:http://wiki.codemongers.com/NginxChs 一 . nginx安装 1. 下载nginx : http://sysoev.ru/nginx/downlo ...

  7. 动态规划——最长公共子序列(LCS)

    /** * @brief longest common subsequence(LCS) * @author An * @data 2013.8.26 **/ #include <iostrea ...

  8. JavaScript学习笔记(四十四) 装饰器

    装饰器模式(Decorator) 在装饰器模式中,可以在运行时给一个对象动态的添加额外的功能.当和静态类打交道的时候(static classes),这可能是一个挑战.但在JavaScript中,对象 ...

  9. Axis2(9):编写Axis2模块(Module)

    Axis2可以通过模块(Module)进行扩展.Axis2模块至少需要有两个类,这两个类分别实现了Module和Handler接口.开发和使用一个Axis2模块的步骤如下: 1. 编写实现Module ...

  10. Qt 多线程与数据库操作需要注意的几点问题

    源地址:http://blog.csdn.net/goldenhawking/article/details/10811409 彻底抛弃MFC, 全面应用Qt 已经不少时间了.除了自己看书按步就班做了 ...