The problems are:
- GUI libraries like to use
ToString
as a default representation for classes. There it needs to be localized. ToString
is used for logging. There it should provide programming related information, is not translated and includes internal states like surrogate keys and enum values.ToString
is used by many string operations which take objects as arguments, for instanceString.Format
, when writing to streams. Depending on the context you expect something different.ToString
is too limited if there are many different representations of the same object, eg. a long and a short form.
Because of the different usages, there are many different kinds of implementation. So they are too unreliable to be really useful.
How should ToString
be implemented to be useful? When should ToString
be used, when should it be avoided?
The .NET Framework documentation says:
This method returns a human-readable string that is culture-sensitive.
There is a similar question, but not the same.