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

前端 未结 4 1026
谎友^
谎友^ 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:48

    The best way I could suggest you is replace all the parameters with an Object. All these parameters would represent some info with which you want to update your data base

    class UpdateInfo
    {
      public string ac {get; set;}
      public string pr {get; set;}
      public string fld {get; set;}
      .
      .
      .
    }
    

    All your validation logic for the each parameter could also go in here.

    public void Update(UpdateInfo obj)
    {
     .
     .
    }
    

提交回复
热议问题