using System; using System.IO; class Program { static void Main(string[] args) { string inputString = "Hello World"; StringReader reader = new StringReader(inputString); int c; while ((c = reader.Read()) != -1) { Console.WriteLine((char)c); } } }
using System; using System.IO; class Program { static void Main(string[] args) { string inputString = "Line 1\nLine 2\nLine 3"; StringReader reader = new StringReader(inputString); string line; while ((line = reader.ReadLine()) != null) { Console.WriteLine(line); } } }In this example, we create a StringReader object from the input string "Line 1\nLine 2\nLine 3". Then, we use the ReadLine method to read each line from the StringReader object and output it to the console. The package library for the System.IO StringReader class is part of the .NET Framework. No additional package installations are required.