The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

BinaryWriter.Write Method (Double)


Writes an eight-byte floating-point value to the current stream and advances the stream position by eight bytes.

Namespace:   System.IO
Assembly:  mscorlib (in mscorlib.dll)

public virtual void Write(
	double value


Type: System.Double

The eight-byte floating-point value to write.

Exception Condition

An I/O error occurs.


The stream is closed.

For a list of common I/O tasks, see Common I/O Tasks.

The following code example shows how to read and write Double data to memory by using the BinaryReader and BinaryWriter classes on top of the MemoryStream class. MemoryStream only reads and writes Byte data.

using System;
using System.IO;

class BinaryRW
    static void Main()
        int i;
        const int arrayLength = 1000;

        // Create random data to write to the stream.
        Random randomGenerator = new Random();
        double[] dataArray = new double[arrayLength];
        for(i = 0; i < arrayLength; i++)
            dataArray[i] = 100.1 * randomGenerator.NextDouble();

        using(BinaryWriter binWriter = 
            new BinaryWriter(new MemoryStream()))
            // Write the data to the stream.
            Console.WriteLine("Writing data to the stream.");
            for(i = 0; i < arrayLength; i++)

            // Create a reader using the stream from the writer.
            using(BinaryReader binReader = 
                new BinaryReader(binWriter.BaseStream))
                    // Return to the beginning of the stream.
                    binReader.BaseStream.Position = 0;

                    // Read and verify the data.
                    Console.WriteLine("Verifying the written data.");
                    for(i = 0; i < arrayLength; i++)
                        if(binReader.ReadDouble() != dataArray[i])
                            Console.WriteLine("Error writing data.");
                    Console.WriteLine("The data was written " +
                        "and verified.");
                catch(EndOfStreamException e)
                    Console.WriteLine("Error writing data: {0}.",

Universal Windows Platform
Available since 4.5
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
© 2015 Microsoft