title: How to build a query string for a URL in C#?
body: <p>A common task when calling web resources from a code is building a query string to including all the necessary parameters. While by all means no rocket science, there are some nifty details you need to take care of like, appending an <code>&amp;</code> if not the first parameter, encoding the parameters etc.</p>
  
  <p>The code to do it is very simple, but a bit tedious:</p>
  
  <pre><code>StringBuilder SB = new StringBuilder();
  if (NeedsToAddParameter A) 
  { 
    SB.Append("A="); SB.Append(HttpUtility.UrlEncode("TheValueOfA")); 
  }
  
  if (NeedsToAddParameter B) 
  {
    if (SB.Length&gt;0) SB.Append("&amp;"); 
    SB.Append("B="); SB.Append(HttpUtility.UrlEncode("TheValueOfB")); }
  }
  </code></pre>
  
  <p>This is such a common task one would expect a utility class to exist that makes it more elegant and readable. Scanning MSDN, I failed to find one&mdash;which brings me to the following question:</p>
  
  <p>What is the most elegant clean way you know of doing the above?</p>