C# TextWriter

C# TextWriter class is an abstract class. It is used to write text or sequential series of characters into file. It is found in System.IO namespace.

Example

Let's see the simple example of TextWriter class to write two lines data.

snippet
using System;
using System.IO;
namespace TextWriterExample
{
    class Program
    {
        static void Main(string[] args)
        {
            using (TextWriter writer = File.CreateText("e:\\f.txt"))
            {
                writer.WriteLine("Hello C#");
                writer.WriteLine("C# File Handling by rookienerd");
            }
            Console.WriteLine("Data written successfully...");
        }
    }
}
Output
Data written successfully...

f.txt:

Hello C#
C# File Handling by rookienerd
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +