title: c# how to post FormUrlEncodedContent when object is not flat
body: <p>Trying to post to the slack api and have a question on how to include the attachment section in my post. I have a method that will look something like </p>
  
  <pre><code> public KeyValuePair&lt;string, string&gt;[] GetParameters()
      {
          List&lt;KeyValuePair&lt;string, string&gt;&gt; parameters = new List&lt;KeyValuePair&lt;string, string&gt;&gt;();
          parameters.Add(new KeyValuePair&lt;string, string&gt;("token", Token));
          parameters.Add(new KeyValuePair&lt;string, string&gt;("channel", Channel));
          parameters.Add(new KeyValuePair&lt;string, string&gt;("text", Text));
          parameters.Add(new KeyValuePair&lt;string, string&gt;("as_user", As_User.ToString()));
          return parameters.ToArray();
      }
  </code></pre>
  
  <p>But my object has an array I need to include for attachments that looks like</p>
  
  <pre><code>public class Attachment
  {
      public string text{get; set;}
      public string pretext{ get; set;}
  }
  </code></pre>
  
  <p>trying to figure out how to include the attachments in the keyvaluepair array that I'm returning here. Or is that maybe not even the right way to do this?</p>
  
  <p>For what its worth this is how I'm creating the post</p>
  
  <pre><code>using (HttpClient client = new HttpClient())
              {
                  var parameters = response.GetParameters();
                  var requestContent = new FormUrlEncodedContent(parameters);
                  HttpResponseMessage r = await client.PostAsync(baseurl, requestContent);
                  HttpContent responseContent = r.Content;
              }
  </code></pre>