title: Passing a list of <string>,<object> parameters to a method C#
body: <p>I have the following parameter being passed. Notice the second parameters contains int and string (<em>it does not always have to be <code>Area</code> and <code>CustomerName</code>, it can be any names</em>):</p>
  <pre><code>UpdateCustomer(customerId, new { Area = 23, CustomerName = &quot;Bob Smith&quot; });
  </code></pre>
  <p>Here is the function</p>
  <pre><code>public void UpdateCustomer(int customerId,
                             dynamic parameters)  // Is is correct to define it as &quot;dynamic&quot; or should it be something else?
  </code></pre>
  <p>My question is how would I do a foreach on the parameters and extract both the name/value of each parameter?</p>
  <p>I get an error on the <code>foreach</code> line:</p>
  <pre><code>// Setup Parameters
  foreach (var v in (parameters as dynamic))
  {
      if (v is KeyValuePair&lt;string, string&gt;)
      {
          // Do stuff
      }
      else if (v is KeyValuePair&lt;string, int&gt;)
      {
          // Do stuff
      }
      else throw new InvalidOperationException();
  }
  </code></pre>
  <p>Thanks in advance</p>