How can I code a C# function to accept a variable number of parameters?
<p>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</p>

<pre><code>public void Update(string ac, string pr, string fld, Int32 intVal = null, double dblVal = null, string strVal = null)
{
</code></pre>

<p>Depending on the value of fld I would want to update a certain field name in my table. </p>

<p>Is there some way I could code up the function parameters so I would not have to supply a long list of possible value types?</p>

<p>Ideally I would like to be able to call this function like this:</p>

<pre><code>Update("key1", "key2", "location", "London");
Update("key1" , "key2", "beds", 2);
Update("key1" , "key2", "price", 123.45);
</code></pre>

<p>Then inside the function update I would like to have:</p>

<pre><code>public void Update(string ac, string pr, xxx, yyy)
    {
        try
        {
            vm.Product = _product.Get(ac, pr);
            vm.Product.xxx = yyy;
            _product.AddOrUpdate(vm.Product);
        }
        catch (Exception e) { log(e); }
    }
</code></pre>

<p>In the xxx I would like to give the field name and yyy the actual value. Maybe inside the function I could do some kind of casting with a case method based on the field name. I only have a small number of field names so that could be easy. Also maybe there is a way I could find the datatype from reflection of the vm class but that's far beyond my knowledge. </p>
