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

  

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. 类型转换构造函数 及使用explicit避免类型自动转换------新标准c++程序设计

    类型转换构造函数:  除复制构造函数外,只有一个参数的构造函数一般可以称作类型转换构造函数,因为这样的构造函数能起到类型自动转换的作用.例如下面的程序: #include<iostream> ...

  2. Ext中setValue和setRawValue

    Ext.getCmp('modifyStatus').setValue(record.get('status').trim()); Ext.getCmp('modifyStatus').setRawV ...

  3. TypeScript入门-类

    ▓▓▓▓▓▓ 大致介绍 在ECMASript6中引入了类这一概念,通过class声明一个类.对于学习过C和C++的人应该不会陌生 ▓▓▓▓▓▓ 类 看一个简单的类: class Greeter { g ...

  4. 根据枚举获取枚举的Description特性值

    首先定义一个枚举:两个值:已确认.未确认. public enum ConfirmStatusEnum { [Description("未确认")] unconfirmed = , ...

  5. opencv学习笔记1

    #对图像的像素处理#法1print("------------------------")image = cv.imread("D:/1.jpeg",cv.IM ...

  6. 设置placeholder的样式

    :-moz-placeholder { /* Mozilla Firefox 4 to 18 */ color: #f00; } ::-moz-placeholder { /* Mozilla Fir ...

  7. select和epoll的实现

    select:fd_set是输入结果参数,每次select之后,还得重置fd_set (1)使用copy_from_user从用户空间拷贝fd_set到内核空间,第一步需要复制所有感兴趣的文件描述符到 ...

  8. 6A - Daydreamin

    #include <iostream> #include <cstdio> using namespace std; typedef long long ll; ll dp[] ...

  9. 转载---<html>与<body>

    关于根元素html以及body的对比,主要是遇到设置背景色的问题,这里转载张鑫旭的关于html和body对比的文.(直接贴过来,是为了以后自己方便看) 原文地址:http://www.zhangxin ...

  10. flask_restful

    from flask_restful import (Resource, reqparse) # 参数解析对象生成 parser = reqparse.RequestParser() parser.a ...