C#参数out和参考参数 [英] c# parmeters of out and reference parameter

查看:59
本文介绍了C#参数out和参考参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么出了问题,并引用了参数?

what is out and ref parameter?

推荐答案

这隐藏在 ^ ].


ref- use to pass by reference in function argument
out-similar to ref but pass out value from the function..below example



类测试
{
无效refDemo(ref int i)
{
i = i * 10;
}
int FindDecimal(f浮点数,dp浮点数)
{
int i =(int)f;
dp = f-i;
返回我;
}
}

类RefExample
{
公共静态无效的Main(string [] args)
{
测试obj = new Test();
int i = 10;
Console.WriteLine(通话之前:" + i);
obj.refDemo(ref i);
Console.WriteLine(通话后i:" + i);
obj.FindDecimal(12.2345f,out float f);
Console.WriteLine(小数点f:" + f);
}
}



class Test
{
void refDemo(ref int i)
{
i= i*10;
}
int FindDecimal(float f,out float dp)
{
int i=(int) f;
dp=f-i;
return i;
}
}

class RefExample
{
public static void Main(string []args)
{
Test obj=new Test();
int i=10;
Console.WriteLine("Before Call i:" + i);
obj.refDemo(ref i);
Console.WriteLine("After Call i:" + i);
obj.FindDecimal(12.2345f,out float f);
Console.WriteLine("Decimal points f:" + f);
}
}


这篇关于C#参数out和参考参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆