HtmlTextWriter.Write HtmlTextWriter.Write HtmlTextWriter.Write HtmlTextWriter.Write Method

定義

將指定資料型別以及任何暫止定位空格寫入輸出資料流。Writes the specified data type to the output stream, along with any pending tab spacing.

多載

Write(Boolean) Write(Boolean) Write(Boolean) Write(Boolean)

將布林值的文字表示以及任何暫止定位空格寫入輸出資料流。Writes the text representation of a Boolean value to the output stream, along with any pending tab spacing.

Write(Char) Write(Char) Write(Char) Write(Char)

將 Unicode 字元的文字表示以及任何暫止定位空格寫入輸出資料流。Writes the text representation of a Unicode character to the output stream, along with any pending tab spacing.

Write(Char[]) Write(Char[]) Write(Char[]) Write(Char[])

將 Unicode 字元陣列的文字表示以及任何暫止定位空格寫入輸出資料流。Writes the text representation of an array of Unicode characters to the output stream, along with any pending tab spacing.

Write(Double) Write(Double) Write(Double) Write(Double)

將雙精度浮點數的文字表示以及任何暫止定位空格寫入輸出資料流。Writes the text representation of a double-precision floating-point number to the output stream, along with any pending tab spacing.

Write(Int32) Write(Int32) Write(Int32) Write(Int32)

將 32 位元組帶正負數的整數之文字表示以及任何暫止定位空格寫入輸出資料流。Writes the text representation of a 32-byte signed integer to the output stream, along with any pending tab spacing.

Write(Int64) Write(Int64) Write(Int64) Write(Int64)

將 64 位元組帶正負數的整數之文字表示以及任何暫止定位空格寫入輸出資料流。Writes the text representation of a 64-byte signed integer to the output stream, along with any pending tab spacing.

Write(Object) Write(Object) Write(Object) Write(Object)

將物件的文字表示以及任何暫止定位空格寫入輸出資料流。Writes the text representation of an object to the output stream, along with any pending tab spacing.

Write(Single) Write(Single) Write(Single) Write(Single)

將單精確度浮點數的文字表示以及任何暫止定位空格寫入輸出資料流。Writes the text representation of a single-precision floating-point number to the output stream, along with any pending tab spacing.

Write(String) Write(String) Write(String) Write(String)

將指定字串以及任何暫止定位空格寫入輸出資料流。Writes the specified string to the output stream, along with any pending tab spacing.

Write(String, Object) Write(String, Object) Write(String, Object) Write(String, Object)

將定位字串和已格式化的字串寫入輸出資料流,使用與 Format(String, Object) 方法相同的語意。Writes a tab string and a formatted string to the output stream, using the same semantics as the Format(String, Object) method, along with any pending tab spacing.

Write(String, Object[]) Write(String, Object[]) Write(String, Object[]) Write(String, Object[])

將格式化字串 (其中包含物件陣列的文字表示) 以及任何暫止定位空格寫入輸出資料流。Writes a formatted string that contains the text representation of an object array to the output stream, along with any pending tab spacing. 這個方法使用的語意與 Format(String, Object[]) 方法相同。This method uses the same semantics as the Format(String, Object[]) method.

Write(Char[], Int32, Int32) Write(Char[], Int32, Int32) Write(Char[], Int32, Int32) Write(Char[], Int32, Int32)

將 Unicode 字元子陣列的文字表示以及任何暫止定位空格寫入輸出資料流。Writes the text representation of a subarray of Unicode characters to the output stream, along with any pending tab spacing.

Write(String, Object, Object) Write(String, Object, Object) Write(String, Object, Object) Write(String, Object, Object)

將格式化字串 (其中包含兩個物件的文字表示) 以及任何暫止定位空格寫入輸出資料流。Writes a formatted string that contains the text representation of two objects to the output stream, along with any pending tab spacing. 這個方法使用的語意與 Format(String, Object, Object) 方法相同。This method uses the same semantics as the Format(String, Object, Object) method.

Write(Boolean) Write(Boolean) Write(Boolean) Write(Boolean)

將布林值的文字表示以及任何暫止定位空格寫入輸出資料流。Writes the text representation of a Boolean value to the output stream, along with any pending tab spacing.

public:
 override void Write(bool value);
public override void Write (bool value);
override this.Write : bool -> unit
Public Overrides Sub Write (value As Boolean)

參數

value
Boolean Boolean Boolean Boolean

要寫入輸出資料流中的 BooleanThe Boolean to write to the output stream.

備註

方法會產生任何暫止的索引標籤,然後再Write呼叫基底方法。 WriteThe Write method generates any tabs that are pending, and then calls the Write base method.

另請參閱

Write(Char) Write(Char) Write(Char) Write(Char)

將 Unicode 字元的文字表示以及任何暫止定位空格寫入輸出資料流。Writes the text representation of a Unicode character to the output stream, along with any pending tab spacing.

public:
 override void Write(char value);
public override void Write (char value);
override this.Write : char -> unit
Public Overrides Sub Write (value As Char)

參數

value
Char Char Char Char

要寫入輸出資料流中的 Unicode 字元。The Unicode character to write to the output stream.

範例

下列程式碼範例將示範如何Write使用方法,藉由使用TagRightChar常數來<img>結束元素的開頭標記。The following code example demonstrates using the Write method to end the opening tag of an <img> element by using the TagRightChar constant.

這個程式碼範例會呈現下列標記:This code example renders the following markup:

<img alt="A custom image">

</img>

// Create a manually rendered <img> element
// that contains an alt attribute.
writer.WriteBeginTag("img");
writer.WriteAttribute("alt", "A custom image.");
writer.Write(HtmlTextWriter.TagRightChar);
writer.WriteEndTag("img");
' Create a manually rendered <img> element
' that contains an alt attribute.
writer.WriteBeginTag("img")
writer.WriteAttribute("alt", "A custom image.")
writer.Write(HtmlTextWriter.TagRightChar)
writer.WriteEndTag("img")

備註

方法會產生任何暫止的索引標籤,然後再Write呼叫基底方法。 WriteThe Write method generates any tabs that are pending, and then calls the Write base method.

另請參閱

Write(Char[]) Write(Char[]) Write(Char[]) Write(Char[])

將 Unicode 字元陣列的文字表示以及任何暫止定位空格寫入輸出資料流。Writes the text representation of an array of Unicode characters to the output stream, along with any pending tab spacing.

public:
 override void Write(cli::array <char> ^ buffer);
public override void Write (char[] buffer);
override this.Write : char[] -> unit
Public Overrides Sub Write (buffer As Char())

參數

buffer
Char[]

要寫入輸出資料流中的 Unicode 字元陣列。The array of Unicode characters to write to the output stream.

範例

本節提供兩個程式碼範例。This section provides two code examples. 第一個範例會示範如何建立字元陣列。The first one demonstrates how to create an array of characters. 第二個範例會示範如何使用陣列。The second one demonstrates how to use the array.

這些程式碼範例會產生下列標記:These code examples generate the following markup:

<label>

hello world

</label>

下列程式碼範例示範如何建立會拼出hello world的字元陣列。The following code example demonstrates how to create an array of characters that spell out hello world. 陣列中包含的SpaceChar是欄位,會在兩個字之間建立空格。Included in the array is the SpaceChar field, which creates a space between the two words.

private char[] testChars = {'h', 'e', 'l', 'l', 'o',
    HtmlTextWriter.SpaceChar ,'w', 'o', 'r', 'l', 'd'};
Private testChars() As Char = _
    {"h"c, "e"c, "l"c, "l"c, "o"c, _
    HtmlTextWriter.SpaceChar, "w"c, "o"c, "r"c, "l"c, "d"c}

下列程式碼範例示範如何使用Write方法,在包含此範例程式碼的控制項包含在頁面中時,將在上述程式碼範例中建立的hello world字元陣列轉譯為頁面。The following code example demonstrates how to use the Write method to render the hello world character array created in the preceding code example to a page, when the control that contains this example code is included in a page.

// Render a character array as the 
// contents of a <label> element.
writer.RenderBeginTag(HtmlTextWriterTag.Label);
writer.Write(testChars);
writer.RenderEndTag();
' Render a character array as the 
' contents of a <label> element.
writer.RenderBeginTag(HtmlTextWriterTag.Label)
writer.Write(testChars)
writer.RenderEndTag()

備註

方法會產生任何暫止的索引標籤,然後再Write呼叫基底方法。 WriteThe Write method generates any tabs that are pending, and then calls the Write base method.

另請參閱

Write(Double) Write(Double) Write(Double) Write(Double)

將雙精度浮點數的文字表示以及任何暫止定位空格寫入輸出資料流。Writes the text representation of a double-precision floating-point number to the output stream, along with any pending tab spacing.

public:
 override void Write(double value);
public override void Write (double value);
override this.Write : double -> unit
Public Overrides Sub Write (value As Double)

參數

value
Double Double Double Double

要寫入輸出資料流中的雙精度浮點數。The double-precision floating-point number to write to the output stream.

範例

下列程式碼範例示範如何使用Write方法來呈現Double.MaxValue欄位的值。The following code example shows how to use the Write method to render the value of the Double.MaxValue field.

這個程式碼範例會產生下列標記:This code example generates the following markup:

<label>

1.79769313486232E+308

</label>

// Use the Write(Double) method to render
// the MaxValue field of the Double structure. 
writer.RenderBeginTag(HtmlTextWriterTag.Label);
writer.Write(Double.MaxValue);
writer.RenderEndTag();
' Use the WriteLine(Double) method to render
' the MaxValue field of the Double structure. 
writer.RenderBeginTag(HtmlTextWriterTag.Label)
writer.WriteLine(Double.MaxValue)
writer.RenderEndTag()

備註

方法會產生任何暫止的索引標籤,然後再Write呼叫基底方法。 WriteThe Write method generates any tabs that are pending, and then calls the Write base method.

另請參閱

Write(Int32) Write(Int32) Write(Int32) Write(Int32)

將 32 位元組帶正負數的整數之文字表示以及任何暫止定位空格寫入輸出資料流。Writes the text representation of a 32-byte signed integer to the output stream, along with any pending tab spacing.

public:
 override void Write(int value);
public override void Write (int value);
override this.Write : int -> unit
Public Overrides Sub Write (value As Integer)

參數

value
Int32 Int32 Int32 Int32

要寫入至輸出資料流的 32 位元組帶正負號的整數。The 32-byte signed integer to write to the output stream.

備註

方法會產生任何暫止的索引標籤,然後再Write呼叫基底方法。 WriteThe Write method generates any tabs that are pending, and then calls the Write base method.

另請參閱

Write(Int64) Write(Int64) Write(Int64) Write(Int64)

將 64 位元組帶正負數的整數之文字表示以及任何暫止定位空格寫入輸出資料流。Writes the text representation of a 64-byte signed integer to the output stream, along with any pending tab spacing.

public:
 override void Write(long value);
public override void Write (long value);
override this.Write : int64 -> unit
Public Overrides Sub Write (value As Long)

參數

value
Int64 Int64 Int64 Int64

要寫入至輸出資料流的 64 位元組帶正負號的整數。The 64-byte signed integer to write to the output stream.

備註

方法會產生任何暫止的索引標籤,然後再Write呼叫基底方法。 WriteThe Write method generates any tabs that are pending, and then calls the Write base method.

另請參閱

Write(Object) Write(Object) Write(Object) Write(Object)

將物件的文字表示以及任何暫止定位空格寫入輸出資料流。Writes the text representation of an object to the output stream, along with any pending tab spacing.

public:
 override void Write(System::Object ^ value);
public override void Write (object value);
override this.Write : obj -> unit
Public Overrides Sub Write (value As Object)

參數

value
Object Object Object Object

要寫入輸出資料流中的物件。The object to write to the output stream.

範例

下列程式碼範例示範如何使用Write方法來呈現CultureInfo.CurrentCulture屬性的值。The following code example shows how to use the Write method to render the value of the CultureInfo.CurrentCulture property.

這個程式碼範例會產生下列標記:This code example generates the following markup:

This is a rendered CultureInfo object.

<bold>

CurrentCulture屬性的值:The value of the CurrentCulture property:

</bold>

// Use the Write method to render an arbitrary
// object, in this case a CultureInfo object. 
writer.Write("This is a rendered CultureInfo Object.");
writer.RenderBeginTag(HtmlTextWriterTag.B);
writer.Write(CultureInfo.CurrentCulture);
writer.RenderEndTag();
' Use the Write method to render an arbitrary
' object, in this case a CultureInfo object.
writer.Write("This is a rendered CultureInfo Object.")
writer.RenderBeginTag(HtmlTextWriterTag.B)
writer.Write(CultureInfo.CurrentCulture)
writer.RenderEndTag()

備註

方法會產生任何暫止的索引標籤,然後再Write呼叫基底方法。 WriteThe Write method generates any tabs that are pending, and then calls the Write base method.

另請參閱

Write(Single) Write(Single) Write(Single) Write(Single)

將單精確度浮點數的文字表示以及任何暫止定位空格寫入輸出資料流。Writes the text representation of a single-precision floating-point number to the output stream, along with any pending tab spacing.

public:
 override void Write(float value);
public override void Write (float value);
override this.Write : single -> unit
Public Overrides Sub Write (value As Single)

參數

value
Single Single Single Single

要寫入輸出資料流中的單精確度浮點數。The single-precision floating-point number to write to the output stream.

範例

下列程式碼範例示範如何使用Write方法來呈現Single.Epsilon欄位的值,這是Single結構的最小可能值。The following code example demonstrates how to use the Write method to render the value of the Single.Epsilon field, which is the smallest possible value of the Single structure.

這個程式碼範例會產生下列標記:This code example generates the following markup:

<b>

1.401298E-45

</b>

// Use the Write(Single) method to render the
// Epsilon field of the Single structure. 
writer.RenderBeginTag(HtmlTextWriterTag.B);
writer.Write(Single.Epsilon);
writer.RenderEndTag();
' Use the Write(Single) method to render the
' Epsilon field of the Single structure. 
writer.RenderBeginTag(HtmlTextWriterTag.B)
writer.Write(Single.Epsilon)
writer.RenderEndTag()

備註

方法會產生任何暫止的索引標籤,然後再Write呼叫基底方法。 WriteThe Write method generates any tabs that are pending, and then calls the Write base method.

另請參閱

Write(String) Write(String) Write(String) Write(String)

將指定字串以及任何暫止定位空格寫入輸出資料流。Writes the specified string to the output stream, along with any pending tab spacing.

public:
 override void Write(System::String ^ s);
public override void Write (string s);
override this.Write : string -> unit
Public Overrides Sub Write (s As String)

參數

s
String String String String

要寫入輸出資料流的字串。The string to write to the output stream.

範例

下列程式碼範例示範如何使用Write方法,在自訂標記專案的開頭和結束記號之間呈現字串。The following code example demonstrates how to use the Write method to render a string between the opening and closing tags of a custom markup element.

這個程式碼範例會產生下列標記:This code example generates the following markup:

<MyTag>

Contents of MyTag

</MyTag>

// Create a non-standard tag.
writer->RenderBeginTag( "MyTag" );
writer->Write( "Contents of MyTag" );
writer->RenderEndTag();
writer->WriteLine();
// Create a non-standard tag.
writer.RenderBeginTag("MyTag");
writer.Write("Contents of MyTag");
writer.RenderEndTag();
writer.WriteLine();
' Create a non-standard tag.
writer.RenderBeginTag("MyTag")
writer.Write("Contents of MyTag")
writer.RenderEndTag()
writer.WriteLine()

備註

方法會產生任何暫止的索引標籤,然後再Write呼叫基底方法。 WriteThe Write method generates any tabs that are pending, and then calls the Write base method.

另請參閱

Write(String, Object) Write(String, Object) Write(String, Object) Write(String, Object)

將定位字串和已格式化的字串寫入輸出資料流,使用與 Format(String, Object) 方法相同的語意。Writes a tab string and a formatted string to the output stream, using the same semantics as the Format(String, Object) method, along with any pending tab spacing.

public:
 override void Write(System::String ^ format, System::Object ^ arg0);
public override void Write (string format, object arg0);
override this.Write : string * obj -> unit
Public Overrides Sub Write (format As String, arg0 As Object)

參數

format
String String String String

包含零或多個格式項目的字串。A string that contains zero or more format items.

arg0
Object Object Object Object

要格式化的物件。An object to format.

範例

下列程式碼範例示範如何使用Write方法,以CurrentCulture屬性的值呈現格式化字串。The following code example shows how to use the Write method to render a formatted string with the value of the CurrentCulture property.

// Use the Write(string, object) method to
// render a formatted string and an object in it.
writer.RenderBeginTag(HtmlTextWriterTag.Label);
writer.Write("The current cultural settings are {0}",
    CultureInfo.CurrentCulture);
writer.RenderEndTag();
' Use the Write(string, object) method to
' render a formatted string and an object in it.
writer.RenderBeginTag(HtmlTextWriterTag.Label)
writer.Write("The current cultural settings are {0}.", _
    CultureInfo.CurrentCulture)
writer.RenderEndTag()

備註

方法會產生任何暫止的索引標籤,然後再Write呼叫基底方法。 WriteThe Write method generates any tabs that are pending, and then calls the Write base method.

另請參閱

Write(String, Object[]) Write(String, Object[]) Write(String, Object[]) Write(String, Object[])

將格式化字串 (其中包含物件陣列的文字表示) 以及任何暫止定位空格寫入輸出資料流。Writes a formatted string that contains the text representation of an object array to the output stream, along with any pending tab spacing. 這個方法使用的語意與 Format(String, Object[]) 方法相同。This method uses the same semantics as the Format(String, Object[]) method.

public:
 override void Write(System::String ^ format, ... cli::array <System::Object ^> ^ arg);
public override void Write (string format, params object[] arg);
override this.Write : string * obj[] -> unit
Public Overrides Sub Write (format As String, ParamArray arg As Object())

參數

format
String String String String

包含零或多個格式項目的字串。A string that contains zero or more format items.

arg
Object[]

要格式化的物件陣列。An object array to format.

範例

本節包含兩個程式碼範例。This section contains two code examples. 第一個範例會示範如何呈現格式化的字串和陣列的內容。The first one demonstrates how to render a formatted string and the contents of an array. 第二個範例會示範如何宣告陣列。The second one demonstrates how to declare the array.

下列程式碼範例示範如何使用Write方法來轉譯格式化的字串和物件陣列的內容,名為。 curPriceTimeThe following code example shows how to use the Write method to render a formatted string and the contents of an object array, named curPriceTime. 方法呼叫會轉譯陣列的第二個成員,然後才呈現第一個成員。The method call renders the second member of the array before it renders the first member.

// Render a formatted string and the
// text representation of an object array,
// myObjectArray, as the contents of
// a <label> element.
writer.RenderBeginTag(HtmlTextWriterTag.Label);
writer.Write("The trade value at {1} is ${0}.", curPriceTime);
writer.RenderEndTag();
' Render a formatted string and the
' text representation of an object array,
' myObjectArray, as the contents of
' a <label> element.
writer.RenderBeginTag(HtmlTextWriterTag.Label)
writer.Write("The trade value at {1} is ${0}.", curPriceTime)
writer.RenderEndTag()

下列程式碼範例將示範如何curPriceTime宣告物件陣列。The following code example demonstrates declaring the curPriceTime object array.

private object[] curPriceTime = {4.25, DateTime.Now};
Private curPriceTime() As Object = {4.25, DateTime.Now}

備註

方法會產生任何暫止的索引標籤,然後再Write呼叫基底方法。 WriteThe Write method generates any tabs that are pending, and then calls the Write base method.

另請參閱

Write(Char[], Int32, Int32) Write(Char[], Int32, Int32) Write(Char[], Int32, Int32) Write(Char[], Int32, Int32)

將 Unicode 字元子陣列的文字表示以及任何暫止定位空格寫入輸出資料流。Writes the text representation of a subarray of Unicode characters to the output stream, along with any pending tab spacing.

public:
 override void Write(cli::array <char> ^ buffer, int index, int count);
public override void Write (char[] buffer, int index, int count);
override this.Write : char[] * int * int -> unit
Public Overrides Sub Write (buffer As Char(), index As Integer, count As Integer)

參數

buffer
Char[]

字元陣列,可從中將文字寫入輸出資料流。The array of characters from which to write text to the output stream.

index
Int32 Int32 Int32 Int32

陣列中開始寫入的索引位置。The index location in the array where writing begins.

count
Int32 Int32 Int32 Int32

要寫入輸出資料流中的字元數。The number of characters to write to the output stream.

範例

本節提供兩個程式碼範例。This section provides two code examples. 第一個範例會示範如何建立字元陣列。The first one demonstrates how to create a character array. 第二個範例會示範如何使用陣列。The second one demonstrates how to use the array.

這些程式碼範例會產生下列標記:These code examples generate the following markup:

<label>

hello

</label>

下列程式碼範例示範如何建立已拼出hello world的字元陣列。The following code example shows how to create an array of characters that spell out hello world. 陣列中包含的SpaceChar是欄位,會在兩個字之間建立空格。Included in the array is the SpaceChar field, which creates a space between the two words.

private char[] testChars = {'h', 'e', 'l', 'l', 'o',
    HtmlTextWriter.SpaceChar ,'w', 'o', 'r', 'l', 'd'};
Private testChars() As Char = _
    {"h"c, "e"c, "l"c, "l"c, "o"c, _
    HtmlTextWriter.SpaceChar, "w"c, "o"c, "r"c, "l"c, "d"c}

程式碼範例的下列部分會使用index Write方法的count和參數,呈現先前範例中所建立之陣列的前五個字元。The following portion of the code example uses the index and count parameters of the Write method to render the first five characters of the array created in the preceding example.

// Render a subarray of a character array
// as the contents of a <label> element.
writer.RenderBeginTag(HtmlTextWriterTag.Label);
writer.Write(testChars, 0, 5);
writer.RenderEndTag();
' Render a subarray of a character array
' as the contents of a <label> element.
writer.RenderBeginTag(HtmlTextWriterTag.Label)
writer.Write(testChars, 0, 5)
writer.RenderEndTag()

備註

方法會產生任何暫止的索引標籤,然後再Write呼叫基底方法。 WriteThe Write method generates any tabs that are pending, and then calls the Write base method.

另請參閱

Write(String, Object, Object) Write(String, Object, Object) Write(String, Object, Object) Write(String, Object, Object)

將格式化字串 (其中包含兩個物件的文字表示) 以及任何暫止定位空格寫入輸出資料流。Writes a formatted string that contains the text representation of two objects to the output stream, along with any pending tab spacing. 這個方法使用的語意與 Format(String, Object, Object) 方法相同。This method uses the same semantics as the Format(String, Object, Object) method.

public:
 override void Write(System::String ^ format, System::Object ^ arg0, System::Object ^ arg1);
public override void Write (string format, object arg0, object arg1);
override this.Write : string * obj * obj -> unit
Public Overrides Sub Write (format As String, arg0 As Object, arg1 As Object)

參數

format
String String String String

包含零或多個格式項目的字串。A string that contains zero or more format items.

arg0
Object Object Object Object

要格式化的物件。An object to format.

arg1
Object Object Object Object

要格式化的物件。An object to format.

範例

下列程式碼範例示範如何使用Write方法來轉譯格式化的字串和CurrentCultureToday屬性的值。The following code example shows how to use the Write method to render a formatted string and the values of the CurrentCulture and Today properties.

// Use the Write(string,object,object) method to
// render a formatted string and two objects 
// in the string.
writer.RenderBeginTag(HtmlTextWriterTag.Label);
writer.Write("The current cultural settings are {0}. Today's date is {1}.",
    CultureInfo.CurrentCulture, DateTime.Today);
writer.RenderEndTag();
' Use the Write(string,object,object) method to
' render a formatted string and two objects 
' in the string.
writer.RenderBeginTag(HtmlTextWriterTag.Label)
writer.Write("The current cultural settings are {0}. Today's date is {1}.", _
    CultureInfo.CurrentCulture, DateTime.Today)
writer.RenderEndTag()

備註

方法會產生任何暫止的索引標籤,然後再Write呼叫基底方法。 WriteThe Write method generates any tabs that are pending, and then calls the Write base method.

另請參閱

適用於