共用方式為


TextTransformation.WriteLine 方法 (String, array<Object )

將格式化字串 (其中包含零個或更多格式規格) 和預設行結束字元附加至產生的文字輸出。每一個格式規格會由對應之物件引數的字串表示所取代。

命名空間:  Microsoft.VisualStudio.TextTemplating
組件:  Microsoft.VisualStudio.TextTemplating.11.0 (在 Microsoft.VisualStudio.TextTemplating.11.0.dll 中)

語法

'宣告
Public Sub WriteLine ( _
    format As String, _
    ParamArray args As Object() _
)
public void WriteLine(
    string format,
    params Object[] args
)
public:
void WriteLine(
    String^ format, 
    ... array<Object^>^ args
)
member WriteLine : 
        format:string * 
        args:Object[] -> unit 
public function WriteLine(
    format : String, 
    ... args : Object[]
)

參數

  • format
    型別:System.String
    包含零個或更多格式規格的字串。
  • args
    型別:array<System.Object[]
    要格式化的物件陣列。

例外狀況

例外狀況 條件
ArgumentNullException

format 為 nullNull 參照 (即 Visual Basic 中的 Nothing)。

-或-

args 為 nullNull 參照 (即 Visual Basic 中的 Nothing)。

FormatException

format 無效。

ArgumentOutOfRangeException

加大基礎 StringBuilder 的值會超過 MaxCapacity

備註

WriteLine 方法可以直接用於文字範本中。

範例

下列程式碼範例示範從文字範本呼叫 WriteLine 方法。將這個程式碼貼到任何文字範本檔案,並執行文字範本轉換,以查看結果。

<#
    string message = @"{0}: This is text to append number {1:F}.";

    Write(message, 0, 0);          //Using the Write method
    WriteLine(null);               //Using the WriteLine method
    WriteLine(null);               //Using the WriteLine method
    
    for(int j=1; j<4; j++)
    {
        WriteLine(message, j, j);  //Using the WriteLine method
    }
#>
<#
    Dim message as String = "{0}: This is text to append number {1:F}."
    Dim j as Integer = 0

    Write(message, 0, 0)          'Using the Write method
    WriteLine(Nothing)            'Using the WriteLine method
    WriteLine(Nothing)            'Using the WriteLine method
    
    For j = 1 To 3

        WriteLine(message, j, j)  'Using the WriteLine method
    Next
#>

這個範例會產生下列輸出:

0: This is text to append number 0.00.

    

1: This is text to append number 1.00.

2: This is text to append number 2.00.

3: This is text to append number 3.00.

.NET Framework 安全性

請參閱

參考

TextTransformation 類別

WriteLine 多載

Microsoft.VisualStudio.TextTemplating 命名空間

GenerationEnvironment

StringBuilder

AppendFormat

MaxCapacity

ArgumentOutOfRangeException

FormatException

ArgumentNullException

其他資源

格式化型別

Numeric Format Strings

Date and Time Format Strings

列舉型別格式字串

How to: Append to the Generated Text