| 区别如下: 1.ref是有进有出,而out是只出不进
 2.使用ref型参数时,传入的参数必须先被初始化。对out而言,必须在方法中对其完成初始化
 3.out适合用在需要retrun多个返回值的地方,而ref则用在需要被调用的方法修改调用者的引用的时候。
 示例代码如下:
 public int  RefValue(int i,ref int j)
 {
 int k = j;
 j =222;
 return i+k;
 }
 public int OutValue(int i, out int j)
 {
 j = 222;
 return i + j;
 }
 private void cmdRef_Click(object sender, EventArgs e)
 {
 int m = 0;
 MessageBox.Show(RefValue(1, ref m).ToString());
 MessageBox.Show(m.ToString());
 }
 private void cmdOut_Click(object sender, EventArgs e)
 {
 int m;
 MessageBox.Show(OutValue(1, out m).ToString());
 MessageBox.Show(m.ToString());
 }
 
 
 
 
 
 
 
 
 |