title: Literal ampersands in System.Uri query string
body: <p>I'm working on a client app that uses a restful service to look up companies by name.
  It's important that I'm able to include literal ampersands in my queries since this character is quite common in company names.</p>
  
  <p>However whenever I pass %26 (the URI escaped ampersand character) to <code>System.Uri</code>, it converts it back to a regular ampersand character! On closer inspection, the only two characters that aren't converted back are hash (%23) and percent (%25).</p>
  
  <p>Lets say I want to search for a company named "Pierce &amp; Pierce":</p>
  
  <pre><code>var endPoint = "http://localhost/companies?where=Name eq '{0}'";
  var name = "Pierce &amp; Pierce";
  Console.WriteLine(new Uri(string.Format(endPoint, name)));
  Console.WriteLine(new Uri(string.Format(endPoint, name.Replace("&amp;", "%26"))));
  Console.WriteLine(new Uri(string.Format(endPoint, Uri.EscapeUriString(name))));
  Console.WriteLine(new Uri(string.Format(endPoint, Uri.EscapeDataString(name))));
  </code></pre>
  
  <p>All four of the above combinations return:</p>
  
  <pre><code>http://localhost/companies?where=Name eq 'Pierce &amp; Pierce'
  </code></pre>
  
  <p>This causes errors on the server side since the ampersand is (correctly) interpreted as a query arg delimiter. What I really need it to return is the original string:</p>
  
  <pre><code>http://localhost/companies?where=Name eq 'Pierce %26 Pierce'
  </code></pre>
  
  <p>How can I work around this behavior without discarding <code>System.Uri</code> entirely?
  I can't replace all ampersands with %26 at the last moment because there will usually be multiple query args involved and I don't want to destroy their delimiters.</p>
  
  <p><strong>Note:</strong> A similar problem was discussed in <a href="https://stackoverflow.com/questions/529857/ampersands-in-urlrewriter-query-strings">this question</a> but I'm specifically referring to <code>System.Uri</code>.</p>