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 資料流。

範例

下列範例顯示 UDT 方法的實 Write 作,其會使用 BinaryWriter 序列化使用者定義二進位格式的 UDT。 Null 字元填補的目的是要確保字串值與雙精度浮點數完全分開,因此,在 Transact-SQL 程式碼中,一個 UDT 會與另一個 UDT 進行比較,字串位元組會與字串位元組進行比較,而雙位元組會與雙位元組進行比較。

// 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);
}

備註

將足夠的資訊寫入二進位資料流程,以允許 Read 方法重新建構 UDT 或使用者定義的匯總。

適用於