packing fields of a class into a byte array in c#
<p>I am trying to create a fast way to convert c# classes into byte array. I thought of serializing the class directly to a byte array using an example I found:</p>

<pre><code>// Convert an object to a byte array
private byte[] ObjectToByteArray(Object obj)
{
   if(obj == null)
       return null;
   BinaryFormatter bf = new BinaryFormatter();
   MemoryStream ms = new MemoryStream();
   bf.Serialize(ms, obj);
   return ms.ToArray();
}
</code></pre>

<p>But the byte array I got contains some other information that are not related to the fields in the class. I guess it is also converting the Properties of the class. </p>

<p>Is there a way to serialize only the fields of the class to a byte array?</p>

<p>Thanks</p>
