ITextSource source = new StringTextSource("Hello, world!"); string text = source.Text; // returns "Hello, world!" foreach (char c in source) { Console.WriteLine(c); } // Output: // H // e // l // l // o // , // // w // o // r // l // d // !
ITextSource source = new FileTextSource("example.txt"); string text = source.Text; // returns the contents of example.txtIn this example, we create a new FileTextSource object with the filename "example.txt". We then use the Text property to get the full text of the file. Overall, the ITextSource interface provides a useful abstraction for working with different types of text sources in C#.