向生成的文本输出追加包含零个或更多格式规范的设置了格式的字符串。 每个格式规范由相应对象参数的字符串表示形式替换。
命名空间:  Microsoft.VisualStudio.TextTemplating
程序集:  Microsoft.VisualStudio.TextTemplating.10.0(在 Microsoft.VisualStudio.TextTemplating.10.0.dll 中)
语法
声明
Public Sub Write ( _
    format As String, _
    ParamArray args As Object() _
)
public void Write(
    string format,
    params Object[] args
)
public:
void Write(
    String^ format, 
    ... array<Object^>^ args
)
member Write : 
        format:string * 
        args:Object[] -> unit 
public function Write(
    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。 | 
备注
Write 方法可直接用于文本模板中。
示例
下面的代码示例演示从文本模板调用 Write 方法。 将此代码粘贴到任何文本模板文件中并运行文本模板转换以查看结果。
<#
    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 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。
请参见
参考
Microsoft.VisualStudio.TextTemplating 命名空间