title: How to turn a struct into a byte array in c#
body: <p>I have a structure in c# with two members:</p>
  
  <pre><code>public int commandID;  
  public string MsgData;  
  </code></pre>
  
  <p>I need to turn both these into a single byte array which then gets sent to a C++ program that will unpack the bytes , it will grab the first `sizeof(int) bytes to get the commandID and then the rest of the MsgData will get used. </p>
  
  <p>What is a good way to do this in c# ?</p>