ref type & out type

    ref type is memory pointer, it  is this pointer of afferent parameter.it means you can change this value of this ref parameter.if you do this ,you can see this parameter value is unchange even if you use this value out of the method.

for example :

using System;
public class MyClass 
{
   
public static void TestRef(ref char i) 
   
{
      
// The value of i will be changed in the calling method
      i = 'b';
   }


   
public static void TestNoRef(char i) 
   
{
      
// The value of i will be unchanged in the calling method
      i = 'c';
   }


   
// This method passes a variable as a ref parameter; the value of the 
   
// variable is changed after control passes back to this method.
   
// The same variable is passed as a value parameter; the value of the
   
// variable is unchanged after control is passed back to this method.
   public static void Main() 
   
{
   
      
char i = 'a';    // variable must be initialized
      TestRef(ref i);  // the arg must be passed as ref
      Console.WriteLine(i);
      TestNoRef(i);
      Console.WriteLine(i);
   }

}


forgive me use this code of MSDN,
I feel this code can clearly explain ref type.

out parameter type is NOT evaluate before it go in this method .
posted on 2005-08-02 17:00  Arthur_wuancheng(大步牛)  阅读(297)  评论(0编辑  收藏  举报