title: Serialize an object in C# and get byte stream
body: <p>I have an object, instance of a <code>Serializable</code> class. I was wondering how can you get this object as a byte stream?</p>
  
  <p>I know I can use <a href="http://msdn.microsoft.com/en-us/library/c5sbs8z9.aspx" rel="noreferrer"><code>BinaryFormatter</code></a> and then use the <code>Serialize</code> method, but this method takes a <code>serializationStream</code> where it writes the serialized object. I want to be able to write it in a file/stream in a specific position so I would like to do something like:</p>
  
  <pre><code>obj = new Something(); // obj is serializable 
  byte[] serialized = obj.serialize(); [*]
  file.write(position, serialized)
  </code></pre>
  
  <p>Is there any way I can do the <code>[*]</code>, to take the bytes of the serialization of an object?</p>