title: Is there a built-in or widely-available uncased string type for .NET
body: <p>I often find myself dealing with strings for which comparison to other strings should ignore case, ie Oracle parameters. I see too much <code>ToUpper()</code> or <code>ToUpperInvariant()</code>. I thought about building a little class that contains a reference to a <code>string</code> whose getters and setters take care of this for me, but I was wondering if this sort of class is built into .NET or some widely-used library. Ideally, such a class would have these advantages:</p>
  
  <ol>
  <li>There would be no need to transform <code>ToUpper()</code> (read the next to see why it isn't just implementing a special comparator)</li>
  <li>It would use less memory (because there would be no need to store <code>char</code>s that have the same value as distinct values) - ie for some subset of <code>char</code> there would be a map taking each index to its oppositely cased index, saving some number of bits per <code>char</code> depending on the language</li>
  </ol>
  
  <p>Edit 0: I get point #1, and I understand why it is better to use  the <code>StringComparison</code> argument, but is it not reasonable to code a separate <code>Type</code> of <code>string</code> that uses this <code>StringComparison</code> by default? Otherwise I am typing that everywhere I see a field of that sort (<code>username</code>, <code>emailAddress</code>, <code>vendorCode</code>, etc)</p>
  
  <p>Edit 1: What about point #2 ? Would it be such a waste of time to shorten all of your <code>char</code> indices by at least 26 in a string-intensive application? Maybe that's not worded correctly...</p>
  
  <p>Edit 2 (corrected math): For example, on #1, say I have a <code>Username</code>-like field which is always <em>persisted</em> in some legacy DB as upper via a stored procedure, and this logic is too pervasive to change throughout all DB procedures.</p>
  
  <p>The usual length of <code>char</code> is 2^16 I think, but suppose I know that the DB treats it as if it has 2^8 at most. So not only do I have to keep explicitly writing the <code>StringComparison</code> over and over again, but the application is wasting 8 bits per <code>char</code>. If I am forced to store about 100000 strings in memory for some operation, that means I am forced to use 10^5*8/(10^6 * 8) = 0.5 MB, which is not very much at all.</p>