What is the C # equivalent for serializing PHP?

I have a code in PHp that I am trying to redo in C #. PHP code has something like fputs ($ file, serialize ($ val))

What could be the NET point, namely the C # equivalent for Serialize ???

+3
source share
3 answers
using (Stream stream = File.Open(filePath, FileMode.Create))
{
    BinaryFormatter bformatter = new BinaryFormatter();
    bformatter.Serialize(stream, myObject);
}
+4
source

As with most cases in .NET, there are many ways to get there, depending on how you plan to use it.

Ways I can think of in .NET BCL:

  • XmlSerializer as directed by Zach
  • BinaryFormatter, as RedFilter points out,
  • WCF DataContract XML / JSON Serializer

WCF DataContract Serializer, XML, JSON , (.NET 3.5 SP1 +), . : http://will.hughesfamily.net.au/20090309/net-35-helper-methods-serialize-objects-to-xml/

+3

.NET provides either binary or XML / SOAP serialization. See MSDN .

0
source

Source: https://habr.com/ru/post/1781676/


All Articles