3.1 FTW
3.1 FTW

Reputation: 51

Saving an Int16 List to a binary file

I need to save data to a binary file. It is of type List<Int16>. How can I write this data to the file?

Upvotes: 0

Views: 303

Answers (3)

Marc Gravell
Marc Gravell

Reputation: 1064184

    using(var file =  File.Create("out.bin"))
    using (var writer = new BinaryWriter(file))
    {
        foreach (short value in list)
        {
            writer.Write(value);
        }
    }

note this assumes you want to use your CPUs endianness.

Upvotes: 3

Stecya
Stecya

Reputation: 23276

Try to use

using(BinaryWriter binWriter = new BinaryWriter(File.Open(fileName, FileMode.Create)))
{
     binWriter.Write(what_you_want);
}

Upvotes: 2

Related Questions