C# program shows the way to use the StringReader class

Category > CSHARP || Published on : Sunday, October 25, 2020 || Views: 719 || StringReader class


Here Pawan Kumar will explain how to use the StringReader class

using System;
using System.IO;
namespace Demo {
	class Program {
		// The main function
		static void Main(string[] args) {
			// Building the string
			System.Text.StringBuilder stringToRead = new
			System.Text.StringBuilder();
			stringToRead.AppendLine("Hello");
			stringToRead.AppendLine("World");
			stringToRead.AppendLine("friend");
			// Using String Reader
			StringReader reader = new
			StringReader(stringToRead.ToString());
			// Reading a line from the string
			string txt = reader.ReadLine();
			Console.WriteLine(txt);
			Console.Read();
		}
	}
}