StringWriter.ToString 方法

返回包含迄今为止写入到当前 StringWriter 中的字符的字符串。

**命名空间:**System.IO
**程序集:**mscorlib(在 mscorlib.dll 中)

语法

声明
Public Overrides Function ToString As String
用法
Dim instance As StringWriter
Dim returnValue As String

returnValue = instance.ToString
public override string ToString ()
public:
virtual String^ ToString () override
public String ToString ()
public override function ToString () : String

返回值

包含写入到当前 StringWriter 中的字符的字符串。

备注

下表列出了其他典型或相关的 I/O 任务的示例。

若要执行此操作...

请参见本主题中的示例...

创建文本文件。

如何:向文件写入文本

写入文本文件。

如何:向文件写入文本

读取文本文件。

如何:从文件读取文本

示例

此代码示例是为 StringWriter(IFormatProvider) 构造函数提供的一个更大示例的一部分。

Console.WriteLine( _
    "Current date and time using the invariant culture: {0}" _
    & vbCrLf & _
    "Current date and time using the Algerian culture: {1}", _
    DateTime.Now.ToString(), strWriter.ToString())
Console.WriteLine(
    "Current date and time using the invariant culture: {0}\n" +
    "Current date and time using the Algerian culture: {1}", 
    DateTime.Now.ToString(), strWriter.ToString());
Console::WriteLine( "Current date and time using the invariant culture: {0}\n"
"Current date and time using the Algerian culture: {1}", DateTime::Now.ToString(), strWriter->ToString() );
Console.WriteLine(
    "Current date and time using the invariant culture: {0}\n" 
    + "Current date and time using the Algerian culture: {1}",
    DateTime.get_Now().ToString(), strWriter.ToString());

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

StringWriter 类
StringWriter 成员
System.IO 命名空间

其他资源

文件和流 I/O
如何:从文件读取文本
如何:向文件写入文本