//ref
class Program
{
public static void Change(ref int x, ref int y)
{
int t = x;
x = y;
y = t;
}
public static void Jia(ref int x)
{
x++;
}
static void Main(string[] args)
{
int a = 15, b = 17;
Change(ref a,ref b);
Jia(ref a);
Jia(ref b);
Console.WriteLine("当前a的值为{0}", a);
Console.WriteLine("当前b的值为{0}", b);
//out
class Program { public static void Change(out int x, ref int y) { int t = x; x = y; y = t; } public static void Jia(out int x) { x++; } static void Main(string[] args) { int a = 15, b = 17; Change(ref a,ref b); Jia(ref a); Jia(ref b); Console.WriteLine("当前a的值为{0}", a); Console.WriteLine("当前b的值为{0}", b);
|