O'Reilly logo

C# Primer: A Practical Approach by Stanley B. Lippman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

3.11. Overriding the Virtual Object Methods

The second issue in the design of a derived class revolves around the three virtual methods that every class implicitly inherits from Object. Recall that by default, ToString() prints out the name of the class. It is generally more useful for a class to display a representation of its internal state. For example, here is the ToString() implementation of our OrQuery class (the lparen and rparen members keep track of any parentheses associated with the query):

 override public string ToString() { StringBuilder sb = new StringBuilder( 8 ); if ( m_lparen != 0 ) gen_lparen( ref sb, m_lparen ); sb.Append( m_lop.ToString() ); sb.Append( " || " ); sb.Append( m_rop.ToString() ); if ( m_rparen != 0 ) gen_rparen( ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required