ref out 的范例
using System;
class RefOut
{
public static void Main(String[] args)
{
int a = 0, b, c = 0, d = 0;
Console.WriteLine("a is normal parameter will not affect the changes after the function call");
Console.WriteLine("b is out parameter will affect the changes after the function call but not necessary to initialize the variable b but should be initialized in the function ParamTest ");
Console.WriteLine("c is ref parameter will affect the changes after the function call and is compulsory to initialize the variable c before calling the function ParamTest");
Console.WriteLine("d is used to store the return value");
d = ParamTest(a, out b, ref c);
Console.WriteLine("a = {0}", a);
Console.WriteLine("b = {0}", b);
Console.WriteLine("c = {0}", c);
Console.WriteLine("d = {0}", d);
Console.Read();
}
public static int ParamTest(int a, out int b, ref int c)
{
a = 10;
b = 20;
c = 30;
return 40;
}
}
class RefOut
{
public static void Main(String[] args)
{
int a = 0, b, c = 0, d = 0;
Console.WriteLine("a is normal parameter will not affect the changes after the function call");
Console.WriteLine("b is out parameter will affect the changes after the function call but not necessary to initialize the variable b but should be initialized in the function ParamTest ");
Console.WriteLine("c is ref parameter will affect the changes after the function call and is compulsory to initialize the variable c before calling the function ParamTest");
Console.WriteLine("d is used to store the return value");
d = ParamTest(a, out b, ref c);
Console.WriteLine("a = {0}", a);
Console.WriteLine("b = {0}", b);
Console.WriteLine("c = {0}", c);
Console.WriteLine("d = {0}", d);
Console.Read();
}
public static int ParamTest(int a, out int b, ref int c)
{
a = 10;
b = 20;
c = 30;
return 40;
}
}

浙公网安备 33010602011771号