Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The following code example creates a writer, which is a class that can take data of some type and convert it to a byte array that can be passed to a stream.
Imports System
Imports System.IO
Public Class MyWriter
Private s As Stream
Public Sub New(stream As Stream)
s = stream
End Sub
Public Sub WriteDouble(myData As Double)
Dim b() As Byte = BitConverter.GetBytes(myData)
' GetBytes is a binary representation of a double data type.
s.Write(b, 0, b.Length)
End Sub
Public Sub Close()
s.Close()
End Sub
End Class
using System;
using System.IO;
public class MyWriter
{
private Stream s;
public MyWriter(Stream stream)
{
s = stream;
}
public void WriteDouble(double myData)
{
byte[] b = BitConverter.GetBytes(myData);
// GetBytes is a binary representation of a double data type.
s.Write(b, 0, b.Length);
}
public void Close()
{
s.Close();
}
}
using namespace System;
using namespace System::IO;
public ref class MyWriter
{
private:
Stream^ s;
public:
MyWriter(Stream^ stream)
{
s = stream;
}
void WriteDouble(double myData)
{
array<Byte>^ b = BitConverter::GetBytes(myData);
// GetBytes is a binary representation of a double data type.
s->Write(b, 0, b->Length);
}
void Close()
{
s->Close();
}
};
In this example, you create a class that has a constructor with a stream argument. From here, you can expose whatever Write methods are necessary. You must convert whatever you are writing to a byte[]. After you obtain the byte[],the Write method writes it to the stream s.