HtmlTextWriter.WriteLine 方法

定義

將資料寫入 HtmlTextWriter 輸出資料流 (如多載參數所指定),後面接著行結束字元字串。 此方法的所有版本會將任何暫止定位空格寫入輸出資料流中。

多載

WriteLine(String, Object, Object)

將任何暫止定位空格及包含兩個物件的文字表示之格式化字串 (後面接著行結束字元字串) 寫入輸出資料流中。

WriteLine(Char[], Int32, Int32)

將任何暫止定位空格及 Unicode 字元的子陣列 (後面接著行結束字元字串) 寫入輸出資料流中。

WriteLine(String, Object[])

將任何暫止定位空格及包含物件陣列的文字表示之格式化字串 (後面接著行結束字元字串) 寫入輸出資料流中。

WriteLine(String, Object)

將任何暫止定位空格及包含物件之文字表示的格式化字串 (後面接著行結束字元字串) 寫入輸出資料流中。

WriteLine(UInt32)

將任何暫止定位空格及 4 位元組、不帶正負號整數的文字表示 (後面接著行結束字元字串) 寫入輸出資料流中。

WriteLine(String)

將任何暫止定位空格及文字字串 (後面接著行結束字元字串) 寫入輸出資料流中。

WriteLine(Single)

將任何暫止定位空格及單精確度浮點數的文字表示 (後面接著行結束字元字串) 寫入輸出資料流中。

WriteLine(Int32)

將任何暫止定位空格及 32 位元組帶正負號整數的文字表示 (後面接著行結束字元字串) 寫入輸出資料流中。

WriteLine(Int64)

將任何暫止定位空格及 64 位元組帶正負號整數的文字表示 (後面接著行結束字元字串) 寫入輸出資料流中。

WriteLine(Double)

將任何暫止定位空格及雙精度浮點數的文字表示 (後面接著行結束字元字串) 寫入輸出資料流中。

WriteLine(Char[])

將任何暫止定位空格及 Unicode 字元的陣列 (後面接著行結束字元字串) 寫入輸出資料流中。

WriteLine(Char)

將任何暫止定位空格及 Unicode 字元 (後面接著行結束字元字串) 寫入輸出資料流中。

WriteLine(Boolean)

將任何暫止定位空格及布林值的文字表示 (後面接著行結束字元字串) 寫入輸出資料流中。

WriteLine()

將行結束字元字串寫入輸出資料流中。

WriteLine(Object)

將任何暫止定位空格及物件的文字表示 (後面接著行結束字元字串) 寫入輸出資料流中。

備註

預設行結束字元字串是歸位字元,後面接著換行字元 (「\r\n」) 。 基 WriteLine 底方法是用來寫入 value 參數。

WriteLine(String, Object, Object)

將任何暫止定位空格及包含兩個物件的文字表示之格式化字串 (後面接著行結束字元字串) 寫入輸出資料流中。

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

參數

format
String

包含零或多個格式項目的字串。

arg0
Object

要格式化的物件。

arg1
Object

要格式化的物件。

範例

下列程式碼範例示範如何使用 WriteLine 方法來呈現格式化字串和屬性的值 CurrentCultureToday

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

備註

預設行結束字元字串是歸位字元,後面接著換行字元 (「\r\n」) 。 方法 WriteLine 會使用與 方法相同的語 Format(String, Object, Object) 意。 基 WriteLine 底方法是用來寫入 value 參數。

另請參閱

適用於

WriteLine(Char[], Int32, Int32)

將任何暫止定位空格及 Unicode 字元的子陣列 (後面接著行結束字元字串) 寫入輸出資料流中。

public:
 override void WriteLine(cli::array <char> ^ buffer, int index, int count);
public override void WriteLine (char[] buffer, int index, int count);
override this.WriteLine : char[] * int * int -> unit
Public Overrides Sub WriteLine (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 方法的 WriteLinecount 參數,轉譯在上述程式碼範例中建立之陣列的前五個字元。

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

備註

預設行結束字元字串是歸位字元,後面接著換行字元 (「\r\n」) 。 基 WriteLine 底方法是用來寫入 value 參數。

另請參閱

適用於

WriteLine(String, Object[])

將任何暫止定位空格及包含物件陣列的文字表示之格式化字串 (後面接著行結束字元字串) 寫入輸出資料流中。

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

參數

format
String

包含零或多個格式項目的字串。

arg
Object[]

要格式化的物件陣列。

範例

本節包含兩個程式碼範例。 第一個示範如何將字串和陣列轉譯至輸出資料流程。 第二個示範如何宣告陣列。

下列程式碼範例示範如何使用 WriteLine 方法,將格式化字串和物件陣列的內容轉譯至輸出資料流程。

// 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.WriteLine("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.WriteLine("The trade value at {1} is ${0}.", curPriceTime)
writer.RenderEndTag()

下列程式碼範例示範如何宣告在上述程式碼範例中轉譯的物件陣列。

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

備註

預設行結束字元字串是歸位字元,後面接著換行字元 (「\r\n」) 。 方法 WriteLine 會使用與 方法相同的語 Format(String, Object[]) 意。 基 WriteLine 底方法是用來寫入 value 方法。

另請參閱

適用於

WriteLine(String, Object)

將任何暫止定位空格及包含物件之文字表示的格式化字串 (後面接著行結束字元字串) 寫入輸出資料流中。

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

參數

format
String

包含零或多個格式項目的字串。

arg0
Object

要格式化的物件。

範例

下列程式碼範例示範如何使用 WriteLine 方法來轉譯具有 屬性值的 CurrentCulture 格式化字串。

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

備註

預設行結束字元字串是歸位字元,後面接著換行字元 (「\r\n」) 。 方法 WriteLine 會使用與 方法相同的語 Format(String, Object) 意。 基 WriteLine 底方法是用來寫入 value 參數。

另請參閱

適用於

WriteLine(UInt32)

重要

此 API 不符合 CLS 規範。

符合 CLS 規範替代方案
System.Web.UI.HtmlTextWriter.WriteLine(Int64)

將任何暫止定位空格及 4 位元組、不帶正負號整數的文字表示 (後面接著行結束字元字串) 寫入輸出資料流中。

public:
 override void WriteLine(System::UInt32 value);
[System.CLSCompliant(false)]
public override void WriteLine (uint value);
[<System.CLSCompliant(false)>]
override this.WriteLine : uint32 -> unit
Public Overrides Sub WriteLine (value As UInteger)

參數

value
UInt32

要寫入輸出資料流中的 4 位元組、不帶正負號的整數。

屬性

備註

預設行結束字元字串是歸位字元,後面接著換行字元 (「\r\n」) 。 基 WriteLine 底方法是用來寫入 value 參數。

另請參閱

適用於

WriteLine(String)

將任何暫止定位空格及文字字串 (後面接著行結束字元字串) 寫入輸出資料流中。

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

參數

s
String

要寫入輸出資料流的字串。

備註

預設行結束字元字串是歸位字元,後面接著換行字元 (「\r\n」) 。 基 WriteLine 底方法是用來寫入 value 參數。

另請參閱

適用於

WriteLine(Single)

將任何暫止定位空格及單精確度浮點數的文字表示 (後面接著行結束字元字串) 寫入輸出資料流中。

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

參數

value
Single

要寫入輸出資料流中的單精確度浮點數。

範例

下列程式碼範例示範如何使用 WriteLine 方法來轉譯 域的值 Single.Epsilon ,這是 結構的最小可能值 Single

此程式碼範例會產生下列標記:

<b>

1.401298E-45

</b>

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

備註

預設行結束字元字串是歸位字元,後面接著換行字元 (「\r\n」) 。 基 WriteLine 底方法是用來寫入 value 參數。

另請參閱

適用於

WriteLine(Int32)

將任何暫止定位空格及 32 位元組帶正負號整數的文字表示 (後面接著行結束字元字串) 寫入輸出資料流中。

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

參數

value
Int32

要寫入至輸出資料流的 32 位元組帶正負號的整數。

備註

預設行結束字元字串是歸位字元,後面接著換行字元 (「\r\n」) 。 基 WriteLine 底方法是用來寫入 value 參數。

另請參閱

適用於

WriteLine(Int64)

將任何暫止定位空格及 64 位元組帶正負號整數的文字表示 (後面接著行結束字元字串) 寫入輸出資料流中。

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

參數

value
Int64

要寫入至輸出資料流的 64 位元組帶正負號的整數。

備註

預設行結束字元字串是歸位字元,後面接著換行字元 (「\r\n」) 。 基 WriteLine 底方法是用來寫入 value 參數。

另請參閱

適用於

WriteLine(Double)

將任何暫止定位空格及雙精度浮點數的文字表示 (後面接著行結束字元字串) 寫入輸出資料流中。

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

參數

value
Double

要寫入輸出資料流中的雙精度浮點數。

範例

下列程式碼範例示範如何使用 WriteLine 方法來呈現域的值 Double.MaxValue

此程式碼範例會產生下列標記:

<label>

1.79769313486232E+308

</label>

// Use the WriteLine(Double) method to render
// the MaxValue field of the Double structure. 
writer.RenderBeginTag(HtmlTextWriterTag.Label);
writer.WriteLine(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()

備註

預設行結束字元字串是歸位字元,後面接著換行字元 (「\r\n」) 。 基 WriteLine 底方法是用來寫入 value 參數。

另請參閱

適用於

WriteLine(Char[])

將任何暫止定位空格及 Unicode 字元的陣列 (後面接著行結束字元字串) 寫入輸出資料流中。

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

參數

buffer
Char[]

要寫入輸出資料流中的字元陣列。

範例

本節提供兩個程式碼範例。 第一個示範如何建立陣列。 第二個示範如何使用該陣列。

這些程式碼範例會產生下列標記:

<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}

下列程式碼範例會 hello world 使用 WriteLine 方法,轉譯在上述範例中建立的字元陣列。

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

備註

預設行結束字元字串是歸位字元,後面接著換行字元 (「\r\n」) 。 基 WriteLine 底方法是用來寫入 value 參數。

另請參閱

適用於

WriteLine(Char)

將任何暫止定位空格及 Unicode 字元 (後面接著行結束字元字串) 寫入輸出資料流中。

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

參數

value
Char

要寫入輸出資料流中的字元。

備註

預設行結束字元字串是歸位字元,後面接著換行字元 (「\r\n」) 。 基 WriteLine 底方法是用來寫入 value 參數。

另請參閱

適用於

WriteLine(Boolean)

將任何暫止定位空格及布林值的文字表示 (後面接著行結束字元字串) 寫入輸出資料流中。

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

參數

value
Boolean

要寫入輸出資料流中的布林。

備註

預設行結束字元字串是歸位字元,後面接著換行字元 (「\r\n」) 。 基 WriteLine 底方法是用來寫入 value 參數。

另請參閱

適用於

WriteLine()

將行結束字元字串寫入輸出資料流中。

public:
 override void WriteLine();
public override void WriteLine ();
override this.WriteLine : unit -> unit
Public Overrides Sub WriteLine ()

範例

下列程式碼範例示範如何使用 WriteLine 方法在轉譯專案之後 <img> 插入一行。

// Control the encoding of attributes.
// Simple known values do not need encoding.
writer->AddAttribute( HtmlTextWriterAttribute::Alt, "Encoding, \"Required\"", true );
writer->AddAttribute( "myattribute", "No "encoding " required", false );
writer->RenderBeginTag( HtmlTextWriterTag::Img );
writer->RenderEndTag();
writer->WriteLine();
// Control the encoding of attributes. 
// Simple known values do not need encoding.
writer.AddAttribute(HtmlTextWriterAttribute.Alt, "Encoding, \"Required\"", true);
writer.AddAttribute("myattribute", "No "encoding " required", false);
writer.RenderBeginTag(HtmlTextWriterTag.Img);
writer.RenderEndTag();
writer.WriteLine();
' Control the encoding of attributes.
' Simple known values do not need encoding.
writer.AddAttribute(HtmlTextWriterAttribute.Alt, "Encoding, ""Required""", True)
writer.AddAttribute("myattribute", "No "encoding " required", False)
writer.RenderBeginTag(HtmlTextWriterTag.Img)
writer.RenderEndTag()
writer.WriteLine()

備註

預設行結束字元字串是歸位字元,後面接著換行字元 (「\r\n」) 。 如需詳細資訊,請參閱WriteLine

另請參閱

適用於

WriteLine(Object)

將任何暫止定位空格及物件的文字表示 (後面接著行結束字元字串) 寫入輸出資料流中。

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

參數

value
Object

要寫入輸出資料流中的物件。

範例

下列程式碼範例示範如何使用 WriteLine 方法,將 屬性的值 CultureInfo.CurrentCulture 轉譯為 控制項。

// Use the WriteLine method to render an arbitrary
// object, in this case a CutltureInfo object.
writer.RenderBeginTag(HtmlTextWriterTag.B);
writer.WriteLine(CultureInfo.CurrentCulture);
writer.RenderEndTag();
' Use the WriteLine method to render an arbitrary
' object, in this case a CutltureInfo object.
writer.RenderBeginTag(HtmlTextWriterTag.B)
writer.WriteLine(CultureInfo.CurrentCulture)
writer.RenderEndTag()

備註

預設行結束字元字串是歸位字元,後面接著換行字元 (「\r\n」) 。 基 WriteLine 底方法是用來寫入 value 參數。

另請參閱

適用於