title: Binary Serialization in c#
body: <p>I am trying to serialize a class object using binary serialization in C#. I have tried and everywhere all I can find that the serialized data goes to a file always in all the examples I have seen.</p>
  
  <p>In my case, I have to store the serialized data in SQL. The following is an example of the method I have created.</p>
  
  <pre><code>//Serializing the List
  public void Serialize(Employees emps, String filename)
  {
      //Create the stream to add object into it.
      System.IO.Stream ms = File.OpenWrite(filename); 
      //Format the object as Binary
  
      BinaryFormatter formatter = new BinaryFormatter();
      //It serialize the employee object
      formatter.Serialize(ms, emps);
      ms.Flush();
      ms.Close();
      ms.Dispose();
  }
  </code></pre>
  
  <p>How can I get the serialized data directly in a string variable? I don't want to use a file.</p>
  
  <p>Please help.</p>