一个方法例如:public string  dbUpdate(string name,string user,string consume,string card,string bankcard,HttpPostedFile  postedFile,string a)
{
}
其中有很多的参数,如果我只想传其中几个参数就要这样写:
dbUpdate(name,"","",card,"",postedFile,"")1.能不能 不这样 不要“”只传我需要的参数。
2.其中 HttpPostedFile  postedFile 参数在它没有值的时候怎么办,怎么在传递的时候没有这个参数就不用传它。谢谢大家!请帮忙 很急!

解决方案 »

  1.   

    你可以用重载.比如下面这样:
    public string aa(string name)
    {
    this.aa(name,"");
    }
    public string aa(string name,string id)
    {
    this.aa(name,id,"");
    }
    public string aa(string name,string id,int type)
    {
    //在这里面处理数据.
    }
      

  2.   

    1.
    你可以再定义一个dbUpdate方法public string  dbUpdate(string name,string card,HttpPostedFile  postedFile)
    {}
    2.一起等待别人回答~~
      

  3.   

    1、重载一个函数:
    public string  dbUpdate(string name,string card,HttpPostedFile  postedFile)
    {
        dbUpdate(name,"","",card,"",postedFile,"");
    }
    2、应该在函数内部先做判断
    if (postedFile == null)
    {//就不处理postedFile这个参数}
    要想不传postedFile这个参数还要再重载一个函数
    public string  dbUpdate(string name,string card)
    {
        dbUpdate(name,"","",card,"",null,"");
    }
    不过无论如何都要对postedFile是否为null进行判断