title: C#: Converting String to Sbyte*
body: <p>My C# code uses a Managed C++ Wrapper. To make a new object of this Wrapper's type, I need to convert String's to Sbyte*'s. A few StackOverflow.com posts discussed how to convert String to byte[], as well as byte[] to sbyte[], but not String to sbyte*.</p>
  
  <p>msdn.social.com offers advice on how to convert a byte array to a string:</p>
  
  <pre><code>&gt;         // convert String to Sbyte*
  &gt;         string str = "The quick brown, fox jumped over the gentleman.";
  &gt;     
  &gt;         System.Text.ASCIIEncoding encoding = new
  &gt;         System.Text.ASCIIEncoding();
  &gt;
  &gt;         Byte[] bytes = encoding.GetBytes(str);
  </code></pre>
  
  <p>However, "bytes" is not of type sbyte*. My following attempts to convert bytes to sbyte* failed:</p>
  
  <blockquote>
  <pre><code>1. Convert.ToSbyte(bytes);
  2. cast:  (sbyte*) bytes;
  </code></pre>
  </blockquote>
  
  <p>Please advise me on how to convert a C# string to an sbyte*.</p>
  
  <p>Also, please talk about any side effects from introducing sbyte*, which I believe is unsafe code. </p>
  
  <p>Thanks,
  Kevin</p>