How can I code a C# function to accept a variable number of parameters?

前端 未结 4 1028
谎友^
谎友^ 2021-01-23 11:21

I have a C# method that I would like to use to update some data. The method could be passed either a string, a double, an integer

public void Update(string ac, s         


        
4条回答
  •  一个人的身影
    2021-01-23 11:57

    If it can be passed one of those parameters, it doesn't sound like you want a variable number; it sounds like you want three different overloads:

    public void Update(string ac, string pr, string fld, Int32 intVal)
    {
    
    }
    
    public void Update(string ac, string pr, string fld, double dblVal)
    {
    
    }
    
    public void Update(string ac, string pr, string fld, string strVal)
    {
    
    }
    

提交回复
热议问题