zoukankan      html  css  js  c++  java
  • C#中params使用

    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

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

  • 相关阅读:
    博客
    欧几里得算法的时间复杂度
    Linux伙伴系统1
    伙伴系统
    websocket
    Colored Sticks POJ
    Repository HDU
    Phone List HDU
    Hat’s Words HDU
    HDU1800 字典树写法
  • 原文地址:https://www.cnblogs.com/ruanmou001/p/3301086.html
Copyright © 2011-2022 走看看