using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ref_out
{
class Program
{
static void Method1(ref int i)
{
i = 44;
}
static void Method2(out int j)
{
j = 55;//out 内部必须要有值
}
static void Method3(ref int h)
{
//ref 内部可以为空,为空时得到的值是初始化值;不为空时得到的是ref传出的值
}
static void Method4(ref int h)
{
h += 11;
}
static void Main()
{
int val1 = 0;
int val2;
int val3 = 66;
int val4 = 66;
Method1(ref val1);//使用ref时 要先初始化。传入传出
Method2(out val2);//可以不初始化,传出值
Method3(ref val3);
Method4(ref val4);
Console.WriteLine(val1);//44
Console.WriteLine(val2);//55
Console.WriteLine(val3);//66
Console.WriteLine(val4);//77
Console.ReadKey();
}
}
}