I want my ConsoleEngine
class to handle the Console.WriteLine()
Method. How do I have to prepare my ConsoleEngine class to override the WriteLine()
method?
You can create a class that derives from TextWriter
:
public class MyWriter : TextWriter
{
public override void Write(char value)
{
//Do something, like write to a file or something
}
public override void Write(string value)
{
//Do something, like write to a file or something
}
public override Encoding Encoding
{
get
{
return Encoding.ASCII;
}
}
}
and set the Console
output to an instance of that class:
Console.SetOut(new MyWriter());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With