using System.IO; ListintegerList = new List (); integerList.Add(1); integerList.Add(2); integerList.Add(3); using (BinaryWriter writer = new BinaryWriter(File.Open("file.bin", FileMode.Create))) { writer.WriteList(integerList); }
using System.IO; ListThis code creates a list of strings and uses the BinaryWriter class to write the list to a binary file called "file.bin". The package library for the BinaryWriter class is in the System.IO namespace of the .NET Class Library.stringList = new List (); stringList.Add("hello"); stringList.Add("world"); stringList.Add("!"); using (BinaryWriter writer = new BinaryWriter(File.Open("file.bin", FileMode.Create))) { writer.WriteList(stringList); }