• C#方法中的params参数类型


    我有一方法如下:
    public string GetByCriteria(params string[] strs)
            
    {
                
    string result = string.Empty;
                
    foreach (string str in strs)
                
    {
                    
    //执行代码
                }


                
    return result;
            }

    params 是数组型参数,根据实参形式选择引用传递或值传递,包含数量可变的参数。
    也就是说,GetByCriteria方法可以接收单个实体,也可以接收实体数组。
    也就不需要重载方法了。
    调用:
     //单个实体
            this.GetByCriteria("test");

            
    //数组
            string[] strs = new string[]{"test","test1"};
            
    this.GetByCriteria(strs);
     
  • 相关阅读:
    webpack
    react 原理
    jest
    input 自动获取焦点
    taro
    html5标签
    webpack
    每日日报
    每日日报
    每日日报
  • 原文地址:https://www.cnblogs.com/maplye/p/445451.html
Copyright © 2020-2023  润新知