C# Program to Demonstrate Stringreader Class

You are currently viewing C# Program to Demonstrate Stringreader Class

C# program to demonstrate StringReader class

//C# program to demonstrate StringReader class.

using System;
using System.IO;

class Program
    const string str = @"This is a cat.
This is dog.
This is elephant.";

    static void ReadLines()
        string line;
        StringReader strReader = new StringReader(str);

        for (int i = 1;true; i++)
            line = strReader.ReadLine();
            Console.WriteLine("Line {0} : {1}",i,line); 

    static void Main()
Line 1 : This is a cat.
Line 2 : This is dog.
Line 3 : This is elephant.
Press any key to continue . . .

Ranjith Kumar

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply