How to use BinaryWriter to write array of integers to binary file in C#

1 Answer

0 votes
using System;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] numbers = { 1, 3, 4, 5, 13, 89, 120, 989 };       
            
            using (BinaryWriter br = new BinaryWriter(File.Open("d:\\file.bin", FileMode.Create)))
            {
                foreach (int i in numbers)
                {
                    br.Write(i);
                }
            }
        }
    }
}

/*
run:
   
file.bin
--------
   Y   x     

*/


answered Mar 15, 2015 by avibootz

Related questions

1 answer 222 views
1 answer 193 views
1 answer 157 views
1 answer 227 views
1 answer 227 views
1 answer 160 views
...