三个高级参数,out、ref、params。
//函数的使用不受限于定义的前后顺序
//out的用法。
class Program
{
//函数该返回什么类型关键字就是什么类型,out是另外附加返回的
public static int GetMybook(int count, out string message)//函数声明时即定义了形参,message直接用
{
message = "你给了我" + count + "本书";
return count;
}
static void Main(string[] args)
{
//方法调用时可以直接在函数内声明实参,格式:”out+返回类型+实参变量名称“,
//实参函数外使用,等同于
//string me;
//int b = GetMybook(5, out me);
int b = GetMybook(5, out string me);
Console.WriteLine(b);
Console.WriteLine(me);
Console.ReadLine();
}
}
原文:https://www.cnblogs.com/yaoyue68/p/14363505.html