XmlWriter.WriteChars(Char[], Int32, Int32) XmlWriter.WriteChars(Char[], Int32, Int32) XmlWriter.WriteChars(Char[], Int32, Int32) XmlWriter.WriteChars(Char[], Int32, Int32) Method

定義

在衍生類別中覆寫時,一次將文字寫入一個緩衝區。When overridden in a derived class, writes text one buffer at a time.

public:
 abstract void WriteChars(cli::array <char> ^ buffer, int index, int count);
public abstract void WriteChars (char[] buffer, int index, int count);
abstract member WriteChars : char[] * int * int -> unit
Public MustOverride Sub WriteChars (buffer As Char(), index As Integer, count As Integer)

參數

buffer
Char[]

包含要寫入之文字的字元陣列。Character array containing the text to write.

index
Int32 Int32 Int32 Int32

緩衝區中的位置指示要寫入的文字開頭。The position in the buffer indicating the start of the text to write.

count
Int32 Int32 Int32 Int32

要寫入的字元數。The number of characters to write.

例外狀況

indexcount 小於零。index or count is less than zero.

-或--or- 緩衝區長度減去 index 小於 count;這個呼叫會導致 Surrogate 字組字元被分隔或寫入無效的 Surrogate 字組。The buffer length minus index is less than count; the call results in surrogate pair characters being split or an invalid surrogate pair being written.

buffer 參數值無效。The buffer parameter value is not valid.

在先前的非同步作業完成前呼叫了 XmlWriter 方法。An XmlWriter method was called before a previous asynchronous operation finished. 在此情況下,會擲回 InvalidOperationException 與「非同步作業已經在進行中」的訊息。In this case, InvalidOperationException is thrown with the message "An asynchronous operation is already in progress."

範例

using (XmlWriter writer = XmlWriter.Create("WriteChars.xml"))
{
	writer.WriteStartDocument();

	char[] ch = new char[4];
	ch[0] = 't';
	ch[1] = 'e';
	ch[2] = 'x';
	ch[3] = 't';

	writer.WriteStartElement("WriteCharacters");
	writer.WriteChars(ch, 0, ch.Length);
	writer.WriteEndElement();
	writer.WriteEndDocument();
}

備註

這個方法可用來一次寫入大量文字的一個緩衝區。This method can be used to write large amounts of text one buffer at a time.

必須執行特殊處理,才能確保WriteChars方法不會跨多個緩衝區寫入不分割 surrogate 字組字元。Special handling must be done to ensure the WriteChars method does not split surrogate pair characters across multiple buffer writes. XML 規格會定義 surrogate 字組的有效範圍。The XML specification defines the valid ranges for surrogate pairs.

這個方法的非同步版本,請參閱WriteCharsAsyncFor the asynchronous version of this method, see WriteCharsAsync.

適用於