Framework Design Guidelines: Overriding Object.ToString()

Continuing in our weekly blog post series that highlights a few of the new image[5]_thumb[2]_thumb[2]_thumbadditions to the Framework Design Guidelines 2nd edition.. This content is found in the Object.ToString section of Chapter 8: Usage Guidelines. Christophe provides some great implementation tips for these guidelines.

DO try to keep the string returned from ToString short.

The debugger uses ToString to get a textual representation of an object to be shown to the developer. If the string is longer than the debugger can display (typically less than one screen length), the debugging experience is hindered.


In term of debugging experience, you should decorate your type with DebuggerDisplayAttribute in addition to overriding ToString for that particular purpose.

DO string formatting based on the current thread culture when returning culture-dependent information.


To be more explicit, use the CultureInfo instance returned by a thread’s CurrentCulture property to format any numeric or date, and the one returned by CurrentUICulture to look up any resource. People are often confused between the two properties.

Comments (4)

  1. What's New says:

    Continuing in our weekly blog post series that highlights a few of the new additions to the Framework

  2. Thank you for submitting this cool story – Trackback from DotNetShoutout

  3. Steven says:

    Isn’t the fact that people are often confused between the CurrentCulture and CurrentUICulture (myself included) property a sign of a design flaw in the framework?

  4. Abjard Shaotka says:

    Great post about framework design guidelines.

    Your book is a great piece of work. I’ve read it and I am using all the things I’ve learned in my day to day work wich C#.

    Nowadays, I am doing some reaserach about multicore programming with C#.

    I bought a new book for beginners by Packt Publishing: "C# 2008 and 2005 Threaded Programming: Beginner’s Guide", by Gaston C. Hillar


    Packt –

    The book is very interesting for beginners who want to exploit multi-core with C# 2005; 2008 and future 2010.

    I found it very interesting. Besides, combining the exercises with the knowledge acquired from your book, multithreading is easier than expected.

    Congratulations and keep posting great articles. I always read them from Mumbai, India.