Share via


IBinarySerialize.Write(BinaryWriter) メソッド

定義

ユーザー定義型 (UDT) またはユーザー定義集計を永続化できるように、バイナリ形式に変換します。

public:
 void Write(System::IO::BinaryWriter ^ w);
public void Write (System.IO.BinaryWriter w);
abstract member Write : System.IO.BinaryWriter -> unit
Public Sub Write (w As BinaryWriter)

パラメーター

w
BinaryWriter

シリアル化した UDT またはユーザー定義集計を格納する BinaryWriter ストリーム。

次の例は、 を使用BinaryWriterして Write UDT をユーザー定義バイナリ形式でシリアル化する UDT の メソッドの実装を示しています。 null 文字の埋め込みの目的は、文字列値が double 値から完全に分離されるようにすることです。これにより、1 つの UDT が Transact-SQL コードで別の UDT と比較され、文字列バイトが文字列バイトと比較され、2 バイトが 2 バイトと比較されます。

// The binary layout is as follows:
//    Bytes 0 - 19: string text, padded to the right with null characters
//    Bytes 20+: Double value

// using Microsoft.SqlServer.Server;
public void Write(System.IO.BinaryWriter w)
{
    int maxStringSize = 20;
    string stringValue = "The value of PI: ";
    string paddedString;
    double value = 3.14159;

    // Pad the string from the right with null characters.
    paddedString = stringValue.PadRight(maxStringSize, '\0');

    // Write the string value one byte at a time.
    for (int i = 0; i < paddedString.Length; i++)
    {
        w.Write(paddedString[i]);
    }

    // Write the double value.
    w.Write(value);
}

注釈

メソッドが UDT またはユーザー定義集計を再構成できるように Read 、十分な情報をバイナリ ストリームに書き込みます。

適用対象