如何为Console.WriteLine覆盖使用自己的类?

时间:2015-09-18 21:03:14

标签: c# override

我希望我的ConsoleEngine类处理Console.WriteLine()方法。如何准备我的ConsoleEngine类以覆盖WriteLine()方法?

1 个答案:

答案 0 :(得分:13)

您可以创建一个派生自<asp:TextBox ID="txtFromDate" runat="server" CssClass="txtDateFrom" name="txtFromDate"></asp:TextBox> $('input[name="txtFromDate"]').val();

的类
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; } } } 输出设置为该类的实例:

Console