HtmlTextWriter.Write 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
將指定的資料類型寫入輸出串流,並連同任何待處理的分頁間距。
多載
| 名稱 | Description |
|---|---|
| Write(Boolean) |
將布林值的文字表示寫入輸出串流,連同任何待處理的分頁間距。 |
| Write(Char) |
將 Unicode 字元的文字表示寫入輸出串流,連同任何待處理的分頁間隔。 |
| Write(Char[]) |
將 Unicode 字元陣列的文字表示寫入輸出串流,並連同任何待處理的分頁間隔。 |
| Write(Double) |
將雙精度浮點數的文字表示寫入輸出串流,並附上任何待處理的分頁間距。 |
| Write(Int32) |
將 32 位元組帶符號整數的文字表示寫入輸出串流,並連同任何待處理的分頁間隔。 |
| Write(Int64) |
將 64 位元組有符號整數的文字表示寫入輸出串流,並連同任何待處理的分頁間距。 |
| Write(Object) |
會將物件的文字表示寫入輸出串流,連同任何待處理的分頁間隔。 |
| Write(Single) |
將單精度浮點數的文字表示寫入輸出串流,並連同任何待處理的分頁間距。 |
| Write(String) |
會將指定的字串寫入輸出串流,連同任何待處理的分頁間隔。 |
| Write(String, Object) |
會將 tab 字串和格式化字串寫入輸出串流,使用與方法相同的 Format(String, Object) 語意,並附上任何待處理的分頁間隔。 |
| Write(String, Object[]) |
會寫入一個格式化字串,包含物件陣列的文字表示到輸出串流,以及任何待處理的分頁間隔。 此方法使用與該 Format(String, Object[]) 方法相同的語意。 |
| Write(Char[], Int32, Int32) |
將 Unicode 字元子陣列的文字表示寫入輸出串流,並附上任何待處理的分頁間隔。 |
| Write(String, Object, Object) |
會寫入一個格式化字串,包含兩個物件的文字表示到輸出串流,以及任何待處理的分頁間隔。 此方法使用與該 Format(String, Object, Object) 方法相同的語意。 |
Write(Char)
將 Unicode 字元的文字表示寫入輸出串流,連同任何待處理的分頁間隔。
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
用來寫入輸出串流的 Unicode 字元。
範例
以下程式碼範例示範使用 Write 該方法結束元素的 <img> 開頭標籤,方法是使用 TagRightChar 常數。
此程式碼範例呈現以下標記:
<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 方法會產生任何待處理的分頁,然後呼叫 Write 基礎方法。
另請參閱
適用於
Write(Char[])
將 Unicode 字元陣列的文字表示寫入輸出串流,並連同任何待處理的分頁間隔。
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 字元陣列。
範例
本節提供兩個程式碼範例。 第一個示範如何創造多元角色。 第二個示範如何使用陣列。
這些程式碼範例會產生以下標記:
<label>
hello world
</label>
以下程式碼範例示範如何建立一組拼出 hello world的字元陣列。 陣列 SpaceChar 中包含欄位,該欄位在兩個字之間創造空格。
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 到頁面,當包含該範例程式碼的控制項被包含在頁面中時。
// 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 方法會產生任何待處理的分頁,然後呼叫 Write 基礎方法。
另請參閱
適用於
Write(Double)
將雙精度浮點數的文字表示寫入輸出串流,並附上任何待處理的分頁間距。
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
雙精度浮點數用來寫入輸出串流。
範例
以下程式碼範例說明如何使用此 Write 方法來渲染欄位的 Double.MaxValue 值。
此程式碼範例會產生以下標記:
<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 方法會產生任何待處理的分頁,然後呼叫 Write 基礎方法。
另請參閱
適用於
Write(Int64)
Write(Object)
會將物件的文字表示寫入輸出串流,連同任何待處理的分頁間隔。
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
寫入輸出串流的物件。
範例
以下程式碼範例說明如何使用此 Write 方法來渲染屬性 CultureInfo.CurrentCulture 的值。
此程式碼範例會產生以下標記:
This is a rendered CultureInfo object.
<bold>
房產價值 CurrentCulture :
</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 方法會產生任何待處理的分頁,然後呼叫 Write 基礎方法。
另請參閱
適用於
Write(Single)
將單精度浮點數的文字表示寫入輸出串流,並連同任何待處理的分頁間距。
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
用單精度浮點數寫入輸出串流。
範例
以下程式碼範例示範如何使用此 Write 方法來渲染欄位的值 Single.Epsilon ,該值是結構中最小的值 Single 。
此程式碼範例會產生以下標記:
<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 方法會產生任何待處理的分頁,然後呼叫 Write 基礎方法。
另請參閱
適用於
Write(String)
會將指定的字串寫入輸出串流,連同任何待處理的分頁間隔。
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
寫入輸出串流的字串。
範例
以下程式碼範例示範如何使用此 Write 方法渲染自訂標記元素開頭與關閉標籤之間的字串。
此程式碼範例會產生以下標記:
<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 方法會產生任何待處理的分頁,然後呼叫 Write 基礎方法。
另請參閱
適用於
Write(String, Object)
會將 tab 字串和格式化字串寫入輸出串流,使用與方法相同的 Format(String, Object) 語意,並附上任何待處理的分頁間隔。
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
包含零個或多個格式項目的字串。
- arg0
- Object
要格式化的物件。
範例
以下程式碼範例說明如何使用此 Write 方法渲染帶有屬性值 CurrentCulture 的格式化字串。
// 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 方法會產生任何待處理的分頁,然後呼叫 Write 基礎方法。
另請參閱
適用於
Write(String, Object[])
會寫入一個格式化字串,包含物件陣列的文字表示到輸出串流,以及任何待處理的分頁間隔。 此方法使用與該 Format(String, Object[]) 方法相同的語意。
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
包含零個或多個格式項目的字串。
- arg
- Object[]
一個物件陣列來格式化。
範例
本節包含兩個程式代碼範例。 第一個示範如何渲染格式化字串及陣列內容。 第二個示範如何宣告陣列。
以下程式碼範例展示了如何使用此 Write 方法來渲染格式化字串及名為 curPriceTime的物件陣列內容。 方法呼叫會先渲染陣列的第二個成員,再渲染第一個成員。
// 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
private object[] curPriceTime = {4.25, DateTime.Now};
Private curPriceTime() As Object = {4.25, DateTime.Now}
備註
該 Write 方法會產生任何待處理的分頁,然後呼叫 Write 基礎方法。
另請參閱
適用於
Write(Char[], Int32, Int32)
將 Unicode 字元子陣列的文字表示寫入輸出串流,並附上任何待處理的分頁間隔。
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[]
這是用來寫入輸出串流文字的字元陣列。
- index
- Int32
寫入開始的陣列索引位置。
- count
- Int32
寫入輸出串流的字元數。
範例
本節提供兩個程式碼範例。 第一個示範如何建立字元陣列。 第二個示範如何使用陣列。
這些程式碼範例會產生以下標記:
<label>
hello
</label>
以下程式碼範例展示了如何建立一個拼寫為 hello world的字元陣列。 陣列 SpaceChar 中包含欄位,該欄位在兩個字之間創造空格。
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 and count 參數來渲染前述範例中陣列的前五個字元。
// 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 方法會產生任何待處理的分頁,然後呼叫 Write 基礎方法。
另請參閱
適用於
Write(String, Object, Object)
會寫入一個格式化字串,包含兩個物件的文字表示到輸出串流,以及任何待處理的分頁間隔。 此方法使用與該 Format(String, Object, Object) 方法相同的語意。
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
包含零個或多個格式項目的字串。
- arg0
- Object
要格式化的物件。
- arg1
- Object
要格式化的物件。
範例
以下程式碼範例說明如何使用此Write方法渲染格式化字串及屬性Today的CurrentCulture值。
// 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 方法會產生任何待處理的分頁,然後呼叫 Write 基礎方法。