title: Using unicode characters bigger than 2 bytes with .Net
body: <p>I'm using this code to generate <code>U+10FFFC</code></p>
  
  <pre><code>var s = Encoding.UTF8.GetString(new byte[] {0xF4,0x8F,0xBF,0xBC});
  </code></pre>
  
  <p>I know it's for private-use and such, but it does display a single character as I'd expect when displaying it. The problems come when manipulating this unicode character. </p>
  
  <p>If I later do this:</p>
  
  <pre><code>foreach(var ch in s)
  {
      Console.WriteLine(ch);
  }
  </code></pre>
  
  <p>Instead of it printing just the single character, it prints two characters (i.e. the string is apparently composed of two characters). If I alter my loop to add these characters back to an empty string like so:</p>
  
  <pre><code>string tmp="";
  foreach(var ch in s)
  {
      Console.WriteLine(ch);
      tmp += ch;
  }
  </code></pre>
  
  <p>At the end of this, <code>tmp</code> will print just a single character. </p>
  
  <p>What exactly is going on here? I thought that <code>char</code> contains a single unicode character and I never had to worry about how many bytes a character is unless I'm doing conversion to bytes. My real use case is I need to be able to detect when very large unicode characters are used in a string. Currently I have something like this:</p>
  
  <pre><code>foreach(var ch in s)
  {
      if(ch&gt;=0x100000 &amp;&amp; ch&lt;=0x10FFFF)
      {
          Console.WriteLine("special character!");
      }
  }
  </code></pre>
  
  <p>However, because of this splitting of very large characters, this doesn't work. How can I modify this to make it work?</p>