共用方式為


HtmlTextWriter.WriteLine 方法

定義

將資料寫入 HtmlTextWriter 輸出串流,依據超載參數指定,接著寫入行終止子字串。 所有版本的此方法都將任何待處理的分頁間距寫入輸出串流。

多載

名稱 Description
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方法來渲染格式化字串及屬性與屬性TodayCurrentCulture值。

// 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方法WriteLine的 and count 參數來渲染前述程式碼中陣列的前五個字元。

// 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 ()

範例

以下程式碼範例示範如何在渲染元素後<img>使用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();
' 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參數。

另請參閱

適用於