C # Difficulty one by one (3):p arams array parameters

Source: Internet
Author: User
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)!

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.