using System; using System.IO; class Program { static void Main() { string path = @"c:\temp\example.txt"; using (TextReader reader = new StreamReader(path)) { char character = (char)reader.Read(); Console.WriteLine(character); } } }
using System; using System.IO; class Program { static void Main() { string input = "Hello, world!"; using (TextReader reader = new StringReader(input)) { while (reader.Peek() != -1) { char character = (char)reader.Read(); Console.WriteLine(character); } } } }In this example, a text reader is created to read the contents of a string variable named "input". The Peek method is used to determine if there are more characters to read. If there are, the Read method is used to read the next character and print it to the console. The System.IO package library is used for file and stream input and output operations in C#.