C# Program to Read All Lines using StreamReader


This is a C# Program to use streamreader to read entire line.

Problem Description

This C# Program Uses StreamReader to Read Entire Line.

Problem Solution

Here with the help of streamreader it reads and displays the entire line from the file.

Program/Source Code

Here is source code of the C# Program to Use StreamReader to Read Entire Line. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

 * C# Program to Use StreamReader to Read Entire Line
using System;
using System.IO;
using System.IO.Compression;
using System.Text;
public sealed class Program
    public static void Main()
        Stream s = new FileStream(@"c:\sri\srip.txt", FileMode.Open);
        using (StreamReader sr = new StreamReader(s, Encoding.UTF8))
            string line;
            while ((line = sr.ReadLine()) != null)
Program Explanation

This C# program is used to use StreamReader to read the entire line. It reads with the help of StreamReader, using while loop checks the line is not equal to null. If the condition is true, then execute the iteration of the loop. Print the entire line from the file.

Note: Join free Sanfoundry classes at Telegram or Youtube
Runtime Test Cases
StreamWriter writes text files. It enables easy and efficient text output. 
It is best placed in a using-statement to ensure it is removed 
from memory when no longer needed. 
It provides several constructors and many methods.

Sanfoundry Global Education & Learning Series – 1000 C# Programs.

If you wish to look at all C# Programming examples, go to 1000 C# Programs.

Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.