December 2001
Intermediate to advanced
416 pages
8h 16m
English
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( ...Read now
Unlock full access