[Serializable]
class BinaryExample
{
public int Height { get; set; }
public int Width { get; set; }
public byte[] Values { get; set; }
}
Schritt 2: Serialisieren und speichern
//using System.Runtime.Serialization.Formatters.Binary; - mscorlib.dll
var fileName = "example.bin";
using (var stream = File.Open(fileName, FileMode.Create))
{
var binaryFormatter = new BinaryFormatter();
binaryFormatter.Serialize(stream, example);
}
Schritt 3: Laden und deserialisieren
BinaryExample loadedExample;
using (var stream = File.Open("example.bin", FileMode.Open))
{
var binaryFormatter = new BinaryFormatter();
loadedExample = (BinaryExample)binaryFormatter.Deserialize(stream);
}
Schlagwörter: binär, Serialisierung, Deserialisierung, Datei speichern