关于这三个关键字之前可以研究一下原本的一些操作

  

using System;
using System.Collections.Generic;
using System.Text; namespace ParamsRefOut
{
class Program
{ static void ChangeValue(int i)
{
i=;
Console.WriteLine("The ChangeValue method changed the value "+i.ToString());
}
static void Main(string[] args)
{
int i = ;
Console.WriteLine("The value of I is "+i.ToString());
ChangeValue(i);
Console.WriteLine("The value of I is " + i.ToString());
Console.ReadLine();
}
}
}

观察运行结果发现

值并没有被改变,也就是说此时的操作的原理可能也是跟以前C语言的函数操作是一样的

本文主要讨论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=;i<list.Length;i++)
{
Console.WriteLine(list[i]);
}
}
static void Main(string[] args)
{
UseParams(,,);
int[] myArray = new int[] {,,};
UseParams(myArray);
Console.ReadLine();
}
}
}

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

using System;
using System.Collections.Generic;
using System.Text; namespace ParamsRefOut
{
class number
{
static void Main()
{
int val = ;
Method(ref val);
Console.WriteLine(val.ToString());
}
static void Method(ref int i)
{
i = ;
}
}
}

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

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

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

    一. using System; using System.Collection.Generic; using System.Text; namespace ParamsRefOut { class ...

  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. react.js学习之路三

    学习react.js,知识点整理: 1.props和state: props是相对于父级来说,固定的不会改变的内容.一般会先定义一个变量,则在父级中进行引用, var user = "liu ...

  2. 如何下载网页上的视频 并且 flv 格式转化成 MP4

    链接:http://www.jb51.net/softjc/222135.html https://jingyan.baidu.com/article/25648fc162f2899190fd0042 ...

  3. 老男孩Day10作业:主机管理程序

    一.作业需求: 1, 运行程序列出主机组或者主机列表 2,选择指定主机或主机组 3,选择主机或主机组传送文件(上传/下载) 4,充分使用多线程或多进程 5,不同主机的用户名,密码,端口可以不同 6,可 ...

  4. bit、Byte、bps、Bps、pps、Gbps的单位的说明及换算

    一.bit与Byte区别 1. bit(比特) 是电脑记忆体的最小单元,在二进制计算机中,每一比特代表0或1的数位信号. 2. Byte(单位字节) 一般表示存储介质大小的单位,数字.字母和特殊符号占 ...

  5. HDU-1431-素数回文(暴力打表)

    素数回文 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  6. 【离散数学】 SDUT OJ 集合的包含

    集合的包含 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Problem Description 已知含n个元素的集合的子集 ...

  7. 【问题记录】Python运行报错:can only concatenate str (not "int") to str

    自己总是写程序时候用 + 拼接的时候忘记变量类型要一致,如下面 frame_num = "1" for i in range(1, frame_num + 1, 1): self. ...

  8. 安装opencv-python

    1.安装包下载:在下面的网址下载对应版本及平台的 .whl 包,再手动安装. https://www.lfd.uci.edu/~gohlke/pythonlibs/ 2.将其拷贝到 Python 目录 ...

  9. Gym - 101908G 二分答案+最大流

    After the end of the truck drivers' strike, you and the rest of Nlogônia logistics specialists now h ...

  10. StyleSheet

    StyleSheet.create()方法 //定义组件 var App = React.createClass({ render:function () { return( <View sty ...