手机
当前位置:查字典教程网 >编程开发 >C#教程 >深入Ref,Out的理解及其使用
深入Ref,Out的理解及其使用
摘要:复制代码代码如下:classProgram{//使用out后必须对变量赋值publicvoidTestOut(outintx,outinty...

复制代码 代码如下:

class Program

{

//使用out后必须对变量赋值

public void TestOut(out int x, out int y)

{

x = 1;

y = 2;

}

//此时传进来的值分别为x1:10,y1:11,输出之后的x1的值为2

public void TestRef(ref int x, ref int y)

{

//引用剪剪那句话传进来的是猪,出来的可能是头牛(很精辟!)

x = 2;

}

static void Main(string[] args)

{

int x;

int y;

Program P1 = new Program();

P1.TestOut(out x,out y);

Console.WriteLine("x={0},y={1}", x, y);

//在使用之前ref必须对变量赋值

int x1 = 10;

int Y1 = 11;

P1.TestRef(ref x1,ref Y1);

Console.WriteLine("x1={0},y1={1}", x1, Y1);

}

}

【深入Ref,Out的理解及其使用】相关文章:

c# 随机函数的使用详解

深入多线程之:内存栅栏与volatile关键字的使用分析

深入c# GDI+简单绘图的具体操作步骤(四)

C# 泛型深入理解介绍

c#中抽象类和接口的详细介绍

深入多线程之:Wait与Pulse的使用详解

深入HTTP head的使用详解

深入c#绘制验证码的详解

深入C#中get与set的详解

深入c# GDI+简单绘图的具体操作步骤(一)

精品推荐
分类导航