using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks; namespace Test
{
class Program
{
static void Main(string[] args)
{
int a=;
//ref传参时必须赋值,但方法体内可不不赋值
RefMethod(ref a);
Console.WriteLine(a);
//out传参时可以不赋值,但方法体内必须赋值
OutMethod(out a);
Console.WriteLine(a);
} static void RefMethod(ref int a)
{
a = ;
} static void OutMethod(out int a)
{
a = ;
}
}
}

C#关键字ref和out的更多相关文章

  1. C#中关键字ref与out的区别【转】

    在C#中,ref与out是很特殊的两个关键字.使用它们,可以使参数按照引用来传递.总的来说,通常我们向方法中传递的是值.方法获得的是这些值的一个拷贝,然后使用这些拷贝,当方法运行完毕后,这些拷贝将被丢 ...

  2. 关键字ref、out

    通常,变量作为参数进行传递时,不论在方法内进行了什么操作,其原始初始化的值都不会被影响: 例如: public void TestFun1() { ; TestFun2(arg); Console.W ...

  3. C#中关键字ref修饰类对象或结构体[转]

    using System; using System.Collections.Generic; using System.Text; namespace CSharpTest { struct Dog ...

  4. 关键字:this、ref、out

    Class1.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; usin ...

  5. 使用C#中的ref关键字,用2个简单例子来说明

    在C#中,如果在方法参数前面加上ref关键字,说明参数传递的是引用,而不是值.如何理解呢? 参数是简单类型的例子 static void Main(string[] args) { string te ...

  6. 《ASP.NET 1200例》ref关键字与out关键字

    REF关键字 ref 关键字会导致通过引用传递的参数,而不是值. 通过引用传递的效果是在方法中对参数的任何改变都会反映在调用方的基础参数中. 引用参数的值与基础参数变量的值始终是一样的. 不要将“通过 ...

  7. C# ref、out、params与值类型参数修饰符

    1.值类型: static void Main(string[] args) { ; ; NumVal(a, b); Console.WriteLine("a={0},b={1}" ...

  8. 关于引用类型作为参数加上ref与不加ref的区别

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.C ...

  9. [C#基础]ref和out的区别

    在C#中通过使用方法来获取返回值时,通常只能得到一个返回值.因此,当一个方法需要返回多个值的时候,就需要用到ref和out,那么这两个方法区别在哪儿呢? MSDN:       ref 关键字使参数按 ...

随机推荐

  1. php 简单说明IoC (php 实例+注释)

    简单说明IoC <?php //Ioc ———— 设计方式 //控制反转 Inversion of Control //依赖关系的转移 //依赖抽象而非实践 //用于解决高层应用依赖 底层组件, ...

  2. Linux下编译安装Apache Http Server

    Linux下编译安装Apache Http Server [TOC] 1.下载httpd-2.4.12.tar.bz2 wget http://mirror.bit.edu.cn/apache/htt ...

  3. 如何给zencart安装image handler插件?

    以下内容均为个人的工作总结,有错误的理解都很正常,所以提醒您,可以参考,但是由此造成的一切后果,本人概不负责. 1 去zencart官网下载一个插件包(注意版本是否匹配相应的zencart版本,我的是 ...

  4. git 使用入门篇

    最近准备给同事培训git,发现了一个不错的资源,在这里:http://www.gitguys.com/topics/creating-a-shared-repository-users-sharing ...

  5. JavaScript基础介绍

    JavaScript组成 •ECMAScript:解释器.翻译 •DOM:Document Object Model •BOM:Browser Object Model –各组成部分的兼容性,兼容性问 ...

  6. PhpExcel笔记,phpExcel中文帮助手册

    下面是总结的几个使用方法 include 'PHPExcel.php'; include 'PHPExcel/Writer/Excel2007.php'; //或者include 'PHPExcel/ ...

  7. Python之队列queue模块使用 常见问题与用法

    python 中,队列是线程间最常用的交换数据的形式.queue模块是提供队列操作的模块,虽然简单易用,但是不小心的话,还是会出现一些意外. 1. 阻塞模式 import queue q = queu ...

  8. 大小端; union

    #include<stdio.h> #include <stdlib.h> typedef union { int m; char a[4]; }Node; int main ...

  9. python virtualenv环境运行django

    python virtualenv环境运行django 安装前准备 检查pip版本与python版本是否一致 [root@localhost bin]# whereis pip pip: /usr/b ...

  10. Java集合中Comparator和Comparable接口的使用

    在Java集合中,如果要比较引用类型泛型的List,我们使用Comparator和Comparable两个接口. Comparable接口 -- 默认比较规则,可比较的 实现该接口表示:这个类的实例可 ...