C Sharp/C# – Writing to a text file

By | May 7, 2011


Use the following example code, if you want to write to a text file using C Sharp/C#.

using System;
using System.IO;

class MainClass
    public static void Main()
        FileStream trialStream = new FileStream("sampleText.txt", FileMode.Create);

        StreamWriter trialWrite = new StreamWriter(trialStream );

        trialWrite.WriteLine("{0} {1}", "CoderzHeaven", 100);


        trialStream .Close();


Leave a Reply

Your email address will not be published. Required fields are marked *