I just came across some code that overrides ToString()
and returns some critical information (not just debug information). Users of this type called ToString()
and parse that critical data.
My opinion, from reading various bits and pieces over the years, is that ToString()
has a rather weak contract
, i.e. override it (if you want) to display some meaningful stuff.
See I said display there? The code that I came across relied on the textual representation of instances of this type to be very specific; adding anything other than what's expected would cause all sorts of problems.
So, my question is, if the textual representation of an object is critical, should ToString()
be used or should a more explicit method/property be used, e.g. AsText
?