C#中params使用

mac2022-06-30  20

1、参数被params修饰即为可变参数,params只能修饰一维数组。

2、给可变参数赋值的时候,可以直接传递数组的元素。

3、在调用的时候,会自动将这些元素封装为一个数组,并将数组传递。

4、可变参数必须放在方法参数的最后。

Eg:

static void TestParams(params int[] arr) { //方法内容 } static void TestParams(int i,int j,params int[] arr)//需放在最后 { //方法内容 } static void Main(string[] args) { int arr={1,2,3,4,5,6,9}; TestParams(arr); //亦可如下 //TestParams(1,2,3,4,5); } View Code

 

注:以上内容均属软谋原创,转载请注明出处。

转载于:https://www.cnblogs.com/ruanmou001/p/3301086.html

最新回复(0)