C#函数的参数传递2(ref\out)
2021-03-21 11:26
标签:fir mat hang parse line turn lin src loading C#函数的参数传递2(ref\out) 标签:fir mat hang parse line turn lin src loading 原文地址:https://www.cnblogs.com/BruceKing/p/11818992.htmlusing System;
namespace class1
{
class program
{
static void Main(string[] args)
{
Console.Write("请输入a=");
double a = double.Parse(Console.ReadLine());
Console.Write("请输入b=");
double b = double.Parse(Console.ReadLine());
Console.WriteLine("First");
Console.Write("\t{0} {1}", a, b);
Swap(a,b);
Console.WriteLine("\nSecond");
Console.WriteLine("\t{0} {1}" ,a,b);
Swap1(ref a, ref b);//实际参数也加上REF
Console.WriteLine("\nThird");
Console.WriteLine("\t{0} {1}", a, b);
Console.Write("请输入r=");
double r = double.Parse(Console.ReadLine());
double s = MianJiZhouChang(r, out double c);//这里的out也可以用ref代替,这个时候要为c赋初值
Console.WriteLine("面积是{0},周长是{1}",s,c);
}
static void Swap(double x, double y) {
double z = x;
x = y;
y = z;
}
///
上一篇:软件包,API,SDK的区别
文章标题:C#函数的参数传递2(ref\out)
文章链接:http://soscw.com/index.php/essay/67156.html