Only one paras keyword is allowed in a method declaration, and that keyword can only be the last.
Using System; /****************************** * chapter:c# Difficulty one by one (iii) * Author: Wang Hongjian * date:2010-1-16 * blog:http://www.51obj.cn/* Email: walkingp@126.com * Description: Array parameter params use * ***************************/namespace Testparams {class Program {public Static class Paramsclass {//<summary>////two parameters, the last parameter is an array parameter///</summary>//<param name= "num" >< /param>//<param name= "args" ></param> public static void Paramsmethod (Int. num,params string[] args) {for Each (string _args in args) {Console.WriteLine (_args);} Console.WriteLine ("Total Num is" + num); Console.readkey (); }} static void Main (string[] args) {string[] strarr ={"Wang Hongjian", "Chenchen", "Dodo"}; int personnum = Strarr.length ; Paramsclass.paramsmethod (Personnum, Strarr); } } }
Operating effect:
The sum of ref, out, and params,ref is the result of the parameter in the reference method, and out is the result of the parameter in the reference method to the main method, while the params passes the variable homogeneous parameter (that is, the array) into the parameter. Use medium ref for the need to invoke data within a referenced method. Out is used to manipulate the main method using a reference method, while Prarams is used for cases where the parameter length is unknown.
The above is the C # difficulty one by one (3):p arams array parameters of the content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!