In general, the method's parameter pass is passed by value, that is, an object is passed as a parameter to the method, and the object is placed into the memory space of the pointer that the parameter object is in (described by C), that is, the object creates a copy at this location, and the copy is destroyed when the method finishes running. The use of this method of transmission takes up the overwhelming majority of routine methods of communication.
Another case is a reference pass, which differs from how the value is passed, that the object is passed to the method without affecting the method parameters, and that the method that is affected by the original parameter value is still returned, that is, MethodInstance (ref _refvalue) calls the method (ref _arg), but _ Refvalue has no effect on method, returning is still the result of _arg influence. It can also be thought that _arg must be assigned before use.
Example:
Another case is a reference pass, which differs from how the value is passed, that the object is passed to the method without affecting the method parameters, and that the method that is affected by the original parameter value is still returned, that is, MethodInstance (ref _refvalue) calls the method (ref _arg), but _ Refvalue has no effect on method, returning is still the result of _arg influence. It can also be thought that _arg must be assigned before use.
Example:
Using System; /****************************** * chapter:c# Difficult points (a) * Author: Wang Hongjian * date:2010-1-11 * blog:http://www.51obj.cn/* Email: Walkingp@126.com * Description: Emphasis on value delivery and reference delivery Method * ***************************/namespace Wang.testref {public class Normalclass {public void Shownormalresult (string name) {name = "Wang Hongjian"; Console.WriteLine (name); }} public class Refclass {//<summary>///reference type ref class///</summary>//<param name= "name" ></param& Gt public void Showrefresult (ref string name) {name = "Wang Hongjian"; Console.WriteLine (name); }} class Program {static void Main (string[] args) {string _name = "Zhou Runfa";//pass parameter #region Value pass parameter mode normalclass n = n EW Normalclass (); N.shownormalresult (_name);//Normal call #endregion #region Reference pass parameter mode refclass o = new Refclass (); O.showrefresult (ref _name);//The result is still a reference to pass the parameter Console.readkey (); #endregion}}}
Operation Result:
The above is the C # difficulty one by one (1): Ref parameter passed content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!