Program streamreader.cs

Demonstrates use of StreamReader object 



using System;
using System.IO;

class Program {

    static void Main() {

        StreamReader sr;
        string from_file = string.Empty;
        

        sr = File.OpenText("myfile.txt");
        from_file = sr.ReadLine();

        if (from_file != null) {

            Console.WriteLine("Here is what was read from the \"myfile.txt\" file\n");
            Console.WriteLine("\"" + from_file + "\"\n");

        } else {

            Console.WriteLine("The file did not contain any text\n");

        }

        Console.Write("Press the Enter key to end the program... ");
        Console.ReadLine();

    }//end method Main()   

}//end class Program