C#函数返回值。
⼀、params.
  可变参数,⽆论有⼏个参数,必须出现在参数列表的最后,可以为可变参数直接传递⼀个对应类型的数组。class Program
{
static void Main(string[] args)
{
Test("msg");
Test("msg", 1, 2, 3);
int[] intArry = new int[] { 1, 2, 3 };
Test("msg", intArry);
}
static void Test(string msg,params int[] args)
{
}
writeline函数}
⼆、ref
  引⽤传递
三、out
  out 参数在使⽤之前必须在⽅法⾥为out参数赋值。
  out参数⽆法获取实参传来的值。所以在主函数中,只需声明函数就⾏。它也是引⽤。
  out⼀般⽤在函数有多个返回值。
  参数前加ref  out 不能算重载。
class Program
{
static void Main(string[] args)
{
Test(out int x);
Console.WriteLine(x);
}
static void Test(out int x)
{
x = 100;
}
}
out 实例:
class Program
{
static void Main(string[] args)
{
Console.WriteLine("输⼊⽤户名");
string id = Console.ReadLine();
Console.WriteLine("输⼊密码");
string psw = Console.ReadLine();
bool isok=Login(id, psw, out string msg);
if (isok)
{
Console.WriteLine(msg);
}
else
{
Console.WriteLine(msg);
}
}
private static bool Login(string id, string psw, out string msg)
{
bool isok = false;
if (id!="admin")
{
msg = "⽤户名错误";
}
if (psw!="123")
{
msg = "密码错误";            }
else
{
isok = true;
msg = "登录成功";            }
return isok ;
}
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。