C Sharp TextWriter

C# TextWriter

Being an abstract class, the C# TextWriter class is found in System.IO namespace to be used for writing text or sequential series of characters into a file.


using System;  
using System.IO;  
namespace Example  
    class content  
        static void Main(string[] args)  
            using (TextWriter writer = File.CreateText("d:\\file.txt"))  
                writer.WriteLine("Hello World."); 
                writer.WriteLine("Good Morning.");  
                writer.WriteLine("How are you?");  
                writer.WriteLine("Today is a great day.");  
                writer.WriteLine("Good Luck.");  

Console Output:

D: file.txt:


In the above example, we are using the TextWriter class to write five lines data into a file.


Content Protection by DMCA.com