C#函数的参数传递2(ref\out)(count)

网友投稿 774 2022-09-11

C#函数的参数传递2(ref\out)(count)

C#函数的参数传递2(ref\out)(count)

using 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;

}

///

/// 使形式参数变成引用传递,加上REF

///

///

///

static void Swap1(ref double x, ref double y)

{

double z = x;

x = y;

y = z;

}

///

/// OUT应用

///

///

///

///

static double MianJiZhouChang(double r,out double ZHOUCHANG) {

double S = Math.PI * r * r;

ZHOUCHANG = 2 * Math.PI * r;

return S;

}

}

}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:「实战篇」oracle client PLSQL 客户端安装详细配置
下一篇:test2
相关文章

 发表评论

暂时没有评论,来抢沙发吧~