c# out

在方法中一般的return只能返回1个参数,当需要返回多个参数时就可以用out
static void Main(string[] args)
{
int n;
bool b = MyTryParse("123", out n);
Console.WriteLine(b);
Console.WriteLine(n);
Console.ReadKey();
}
 
public static bool MyTryParse(string s, out int result)
{
result = 0;
try
{
result = Convert.ToInt32(s);
return true;
}
catch
{
return false;
}
}

 

posted @ 2023-12-18 17:18  四月柳巷  阅读(23)  评论(0编辑  收藏  举报