C # Pain-breaking (3):p arams array parameter _c# tutorial

Source: Internet
Author: User
Tags static class
Only one paras keyword is allowed in the method declaration, and the keyword can only be the last one.
Copy Code code as follows:

Using System;

/******************************
* chapter:c# difficulties one by one break (three)
* Author: Wang Hongjian
* date:2010-1-16
* blog:http://www.51obj.cn/
* email:walkingp@126.com
* Description: Use of array parameter params
* ***************************/
Namespace Testparams
{
Class Program
{
public static Class Paramsclass
{
<summary>
Two parameters, last argument is an array parameter
</summary>
<param name= "num" ></param>
<param name= "args" ></param>
public static void Paramsmethod (int num,params string[] args)
{
foreach (String _args in args)
{
Console.WriteLine (_args);
}
Console.WriteLine ("Total Num" + num);
Console.readkey ();
}
}
static void Main (string[] args)
{
String[] Strarr ={"Wang Hongjian", "Chenchen", "Dodo"};
int personnum = Strarr.length;
Paramsclass.paramsmethod (Personnum, Strarr);
}
}
}

Operation Effect:

Summarizing ref, out, and params,ref is the result of the parameter influence within the reference method, out is the result of the parameter return to the main method in the reference method, and the params is passing the variable homogeneous parameter (that is, the array) into the parameter. Use the medium ref for the data that needs to be invoked within the reference method. Out is used to manipulate the main method using a reference method, and prarams is used for situations where the parameter length is unknown.

SOURCE download

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.