CSharp基础 专题
专题目录
您的位置:csharp > CSharp基础 专题 > C# TextWriter类
C# TextWriter类
作者:--    发布时间:2019-11-20

c# textwriter类是一个抽象类。它用于将文本或连续的字符串写入文件。它在system.io命名空间中定义。

c#textwriter示例

让我们来看看textwriter类的简单例子,演示如何使用它来写入两行数据。

using system;
using system.io;
namespace textwriterexample
{
    class program
    {
        static void main(string[] args)
        {
            using (textwriter writer = file.createtext("e:\\textwriter.txt"))
            {
                writer.writeline("hello c#, textwriter");
                writer.writeline("c# file handling by h3.com");
            }
            console.writeline("data written successfully...");
        }
    }
}

执行上面示例代码后,打开textwriter.txt得到以下结果 -

hello c#, textwriter
c# file handling by h3.com

网站声明:
本站部分内容来自网络,如您发现本站内容
侵害到您的利益,请联系本站管理员处理。
联系站长
373515719@qq.com
关于本站:
编程参考手册