编写一个排序方法,使用ref参数,把三个整型实参按从小到大排好序。
//编写 ref方法
public static void TestFunc2(ref int x, ref int y,ref int z)
{
int t;
if (x > y)
{
t = x;
x = y;
y = t;
}
if (x > z)
{
t = x;
x = z;
z = t;
}
if (y > z)
{
t = y;
y = z;
z = t;
}
}
static void Main(string[] args)
{
//对此类方法的调用
//ref 三个整型实参排序
int n1 = 9, n2 = 8, n3 = 5;
TestFunc2(ref n1,ref n2,ref n3);
Console.WriteLine("调用后:n1={0},n2={1},n3={2}",n1,n2,n3);
Console.ReadLine();
}