string path = @"C:\test\example.txt"; using (StreamReader reader = new StreamReader(path)) { int nextChar = reader.Peek(); if (nextChar != -1) { Console.WriteLine("The next character is: " + (char)nextChar); } }
TextReader reader = Console.In; if (reader.Peek() == 45) { Console.WriteLine("The next character is a dash."); }In this example, we create a TextReader that reads from the console input stream. We use the Peek method to read the next character without advancing the reader position, and check if it equals 45 (which is the character code for a dash). If it does, we print a message to the console.