title: C# ushort[] to string conversion; is this possible?
body: <p>I have a very painful library which, at the moment, is accepting a C# string as a way to get arrays of data; apparently, this makes marshalling for pinvokes easier.  </p>
  
  <p>So how do I make a ushort array into a string by bytes?  I've tried:</p>
  
  <pre><code>int i;
  String theOutData = "";
  ushort[] theImageData = inImageData.DataArray;
   //this is as slow like molasses in January
   for (i = 0; i &lt; theImageData.Length; i++) {
       byte[] theBytes = System.BitConverter.GetBytes(theImageData[i]);
       theOutData += String.Format("{0:d}{1:d}", theBytes[0], theBytes[1]);
   }
  </code></pre>
  
  <p>I can do it this way, but it doesn't finish in anything remotely close to a sane amount of time.</p>
  
  <p>What should I do here?  Go unsafe?  Go through some kind of IntPtr intermediate?</p>
  
  <p>If it were a char* in C++, this would be significantly easier...</p>
  
  <p>edit: the function call is</p>
  
  <pre><code>DataElement.SetByteValue(string inArray, VL Length);
  </code></pre>
  
  <p>where VL is a 'Value Length', a DICOM type, and the function itself is generated as a wrapper to a C++ library by SWIG.  It seems that the representation chosen is string, because that can cross managed/unmanaged boundaries relatively easily, but throughout the C++ code in the project (this is GDCM), the char* is simply used as a byte buffer.  So, when you want to set your image buffer pointer, in C++ it's fairly simple, but in C#, I'm stuck with this weird problem.</p>
  
  <p>This is hackeration, and I know that probably the best thing is to make the SWIG library work right.  I really don't know how to do that, and would rather a quick workaround on the C# side, if such exists.</p>