The text of this article is not in this database — only its details are. The old site it was published on is gone, but the Internet Archive kept a copy: How to: Read and Write Binary file in C#
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment
It is the same account you read, post and publish with — and you will come straight back to this page.

Harun OconnellPosted Jan 31, 2023, 8:40 PM
Public void SaveBin(string name) { FileStream fs = new FileStream($"{name}.bin", FileMode.Create); BinaryFormatter formatter = new BinaryFormatter(); try { formatter.Serialize(fs, this); } catch (SerializationException e) { Console.WriteLine("Failed to serialize. Reason: " + e.Message); throw; } finally { fs.Close(); } } public object ReadBin(string name) { Class class; FileStream fs = new FileStream($"{name}.bin", FileMode.Open); try { BinaryFormatter formatter = new BinaryFormatter(); class = (Class)formatter.Deserialize(fs); } catch (SerializationException e) { Console.WriteLine("Failed to deserialize. Reason: " + e.Message); throw; } finally { fs.Close(); } return class; }