outref(C#-7)

Posted on Posted in c#
Tips: 本文创建于2013年12月18日,已超过 2 年,内容或图片可能已经失效!

[code lang="csharp"]
//out 关键字
static void Main(string[] args)
{
int number;
int result = Test(out number);
Console.WriteLine("number={0},result={1}",number,result);
Console.ReadKey();
}
static int Test(out int a)
{
a = 10; //一旦有out,必须赋值
return a;
}
//ref既可以传进,也可以传出
static void Main(string[] args)
{
int number = 100;
Test(ref number);
Console.WriteLine("number={0}",number);
Console.ReadKey();
}
static int Test(ref int a)
{
a = 10;
return a;
}
[/code]

» 转载请注明来源:若我若鱼 » outref(C#-7)

Leave a Reply

Your email address will not be published. Required fields are marked *

fifteen + six =