一、

using System;

using System.Collection.Generic;

using System.Text;

namespace ParamsRefOut

{

class Program

{

static void ChangeValue(int i)

{

i=5;

Console.WriteLine("The ChangeValue method changed the value "+i.ToString());

}

static void Main(string[] args)

{

int i=10;

Console.WriteLine("The value of I is"+i.ToString());

ChangeValue(i);

Console.WriteLine("The value of I is"+i.ToString());

Console.ReadLine();

}

}

}

本文主要讨论params关键字,ref关键字,out关键字

1)params关键字,官方给出的解释为用于方法参数长度不定的情况。有时候不能确定一个方法的方法参数到底有多少个,可以使用params关键字来解决问题

using System;

using System.Collections.Generic;

using System.Text;

namespace ParamsRefOut

{

class number

{

public static void UseParams(params int[] list)

{

for(int i=0;i<list.Length;i++)

{

Console.WriteLine(list[i]);

}

}

static void Main(string[] args)

{

UseParams(1,2,3);

int[] myArray=new int[3]{10,11,12};

UseParams(myArray);

Console.ReadLine();

}

}

}

2)ref关键字:使用引用类型参数,在方法中对参数所做的任何更改都将反应在该变量中

using System;

using System.Collections.Generic;

using System.Text;

namespace ParamsRefOut

{

class number

{

static void Main()

{

int val=0;

Method(ref val);

Console.WriteLine(val.ToString());

}

static void Method(ref int i)

{

i=44;

}

}

}

(3)out关键字:out与ref相似但是out无需进行初始化

C# 中三个关键字params,Ref,out的更多相关文章

  1. C#中三个关键字params,Ref,out

    关于这三个关键字之前可以研究一下原本的一些操作 using System; using System.Collections.Generic; using System.Text; namespace ...

  2. C#中的参数关键字params

    class 参数 { public void doSome(string str,params int[] values){ ) { ; i < values.Length; i++) { Co ...

  3. (Gorails视频)使用推广链接(params[:ref]),增加注册用户!

    用一个链接进行用户的注册推广: 我的git:   https://github.com/chentianwei411/embeddable_comments 用途:比如推广,拉朋友注册,给推广码,用这 ...

  4. 浅谈c#的三个高级参数ref out 和Params C#中is与as的区别分析 “登陆”与“登录”有何区别 经典SQL语句大全(绝对的经典)

    浅谈c#的三个高级参数ref out 和Params   c#的三个高级参数ref out 和Params 前言:在我们学习c#基础的时候,我们会学习到c#的三个高级的参数,分别是out .ref 和 ...

  5. 浅谈c#的三个高级参数ref out 和Params

    c#的三个高级参数ref out 和Params 前言:在我们学习c#基础的时候,我们会学习到c#的三个高级的参数,分别是out .ref 和Params,在这里我们来分别的讲解一下,在这里的我们先不 ...

  6. PHP中this,self,parent三个关键字

    this,self,parent三个关键字从字面上比较好理解,分别是指这.自己.父亲. this是指向当前对象的指针(姑且用C里面的指针来看吧)self是指向当前类的指针parent是指向父类的指针( ...

  7. c#中的Out, params,ref 细说并沉淀

    1. Out,params,ref之前先记录平时用的最多的按值传递参数的情况,当然默认情况下参数传入函数的默认行为也是按值传递的. 1: //默认情况下参数会按照值传递 2: static int a ...

  8. C/C++中static,const,inline三种关键字详细总结

    一.关于staticstatic 是C++中很常用的修饰符,它被用来控制变量的存储方式和可见性,下面我将从 static 修饰符的产生原因.作用谈起,全面分析static 修饰符的实质. static ...

  9. php中this,self,parent三个关键字的区别辨析

    php中this,self,parent三个关键字的区别辨析 一.总结 一句话总结:this是指向对象实例的一个指针,self是对类本身的一个引用,parent是对父类的引用. 1.self关键字使用 ...

随机推荐

  1. 关于可图化序列的一点结论 NEU 1429

    Graphic Sequence A graphic sequence is a sequence of numbers which can be the degree sequence of som ...

  2. Python之数据结构:元组

    一.元组 tupleA=(1,2,3,4,5,6) print tupleA 1.元组支持的运算符 tup1+tup2 tup1*2 3 in tup2 for i in tup2: print i ...

  3. Flask deployment on gunicorn with flask script

    https://stackoverflow.com/questions/34265870/flask-deployment-on-gunicorn-with-flask-script 依赖 Flask ...

  4. chrome浏览器警告:Failed to decode downloaded font:

    使用iconfont字体时chrome报错 Failed to decode downloaded font: 在服务器设置一下自己定义MIME类型. 扩展名: .woff Mime类型:applic ...

  5. 【HDOJ5951】Winning an Auction(博弈DP)

    题意:A和B两个人做一个拍卖游戏.每一轮两人分别给出一个价格,出价高者获得该轮的物品,出价相同则奇数轮A优先,偶数轮B优先. 两个人的目标都是最大化自己的商品数量,给定轮数n与两人分别的总资金a,b, ...

  6. 获取所有querystring变量名

    原文发布时间为:2009-12-04 -- 来源于本人的百度文章 [由搬家工具导入] protected void Page_Load(object sender, EventArgs e)    { ...

  7. HTML 文档之 Head 最佳实践

    语言 在 html 标签中通过 lang 属性进行明确的语言声明,将会有助于翻译,英文.简体中文和繁体中文网页所属性值如下: <html lang="en"> < ...

  8. Ncut matlab 代码bug 修复

    先说平台: win7 x64,matlab 2012a x64,亲测运行. ncut 是个图像切割方法,以后再回顾具体算法吧,网上很多流程的是Jianbo Shi 这位2000年写的,名字应该是:Da ...

  9. why not ovp protection ?

    HW MSM8917 PM8937 PMI8940 Question : Recently, I connect usb cable with 10V to the phone. Why does t ...

  10. AC日记——仙岛求药 openjude 2727

    仙岛求药 思路: bfs: 来,上代码: #include <cstdio> #include <cstring> #include <iostream> #inc ...