I have a piece of code working that serialized a string into XML with XmlSerializer. I want to serialize the same string into binary and Not xml, I have tried different codes but none working, if possible please rewrite the following code to output me a serialized binary and store it in a variable.
public class SerialTest
{
public static void Main(string[] s)
{
String test = "ASD";
string serializedData = string.Empty;
XmlSerializer serializer = new XmlSerializer(test.GetType());
using (StringWriter sw = new StringWriter())
{
serializer.Serialize(sw, test);
serializedData = sw.ToString();
Console.WriteLine(serializedData);
Console.ReadLine();
}
}
}
What I actually want is to have a code that serialize an object and give me the serialized binary as output in a variable and not XML.