title: Using Dictionary Parameters as Optional Arguments when Calling Method
body: <p>I'm presently trying to use a dictionary values to name optional parameters when invoking a method. I'm not sure this is possible with c# but I do something similar with queries using dynamic SQL.</p>
  
  <pre><code>string[] dobArrayKey = {"dob: "};
  string[] dobArrayValue = {txtDob.Text};
  string[] ptntNumArrayKey = { "PatientID: " };
  string[] ptntNumArrayValue = { txtOfficeMR.Text};
  string[] nameArrayKey = { "FirstName: ", "LastName: " };
  string[] nameArrayValue = { txtFirstname.Text, txtLastname.Text };
  
  List&lt;List&lt;string&gt;&gt; searchResults = new List&lt;List&lt;string&gt;&gt;();
  
  
  Dictionary&lt;string[], string[]&gt; searchCriteria = new Dictionary&lt;string[], string[]&gt; 
  { 
      {dobArrayKey,dobArrayValue}
      ,{ptntNumArrayKey,ptntNumArrayValue}
      ,{nameArrayKey,nameArrayValue}
  };
  
  foreach (var item in searchCriteria)
  {
      if (item.Value[0] != "" &amp;&amp; item.Value[0] != null)
      {
          searchResults.Add(new List&lt;string&gt;());
  
          for (int x = 0; x &lt;= item.Key.Count(); x++)
          {
              string strJSON = doPatientSearch(Convert.ToInt32(au.UserID)
                  , Convert.ToInt32(Session["PracticeID"]), au.SessionID, item.Key[x].ToString() : item.Value[x].ToString() );         
  
              PatientSearchResponse ptLi = JsonConvert.DeserializeObject&lt;PatientSearchResponse&gt;(json2);
  
              foreach (PatientList3 patient in ptLi.PatientList)
              {
                  searchResults[x].Add(patient.PatientNumber);
              }
  
          }
      }
  }
  
  public static string doPatientSearch(int UserID, int PracticeID, string SessionID, string PatientID = null,
          ,string first = null, string last = null, string dob = null,  string social = null)
  {
      //search
  }
  </code></pre>
  
  <p>My colleague suggested I change the method itself by removing all of the optional parameters and instead passing through a dictionary that contains all of the parameters and handling them inside the method.</p>
  
  <p>I think that would work, but for curiosities sake I wanted to get some feedback and find out whether or not something like I'm attempting to do in the above code is possible.</p>
  
  <p>If it is impossible but there is another way of achieving the desired outcome I'd love to see your suggestions.</p>
  
  <p>Thank you in advance.</p>