C# difficulties are broken down one by one (3): params array parameters

黄舟
Release: 2016-12-22 14:06:54
Original
1745 people have browsed it

Only one paras keyword is allowed in a method declaration, and this keyword can only be the last one.

using System; 

/****************************** 
* Chapter:C#难点逐个击破(三) 
* Author:王洪剑 
* Date:2010-1-16 
* Blog:http://www.51obj.cn/ 
* Email:walkingp@126.com 
* Description:数组参数params的使用 
* ***************************/ 
namespace TestParams 
{ 
class Program 
{ 
public static class ParamsClass 
{ 
/// <summary> 
/// 两个参数,最后一个参数为数组参数 
/// </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 is " + num); 
Console.ReadKey(); 
} 
} 
static void Main(string[] args) 
{ 
string[] strArr ={"Wang Hongjian","ChenChen","Dodo" }; 
int personNum = strArr.Length; 
ParamsClass.ParamsMethod(personNum, strArr); 
} 
} 
}
Copy after login

Operating effect:

C# difficulties are broken down one by one (3): params array parameters

Summarize ref, out and params. ref is the parameter in the reference method that affects the result; out is the parameter in the reference method that returns the result to the main method; and params is the variable parameter of the same type (i.e. Array) passed in parameters. In use, ref is used to call the data in the reference method. out is used to operate the main method using reference methods, while prarams is used when the parameter length is unknown.

The above is the content of C# difficulties one by one (3): params array parameters. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template