title: C# debugging: [DebuggerDisplay] or ToString()?
body: <p>There are two ways to increase the usefulness of debugging information instead of seeing <code>{MyNamespace.MyProject.MyClass}</code> in the debugger. </p>
  
  <p>These are the use of <a href="https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.debuggerdisplayattribute" rel="noreferrer"><code>DebuggerDisplayAttribute</code></a> and the <code>ToString()</code> method.</p>
  
  <pre><code>using System.Diagnostics;
  ...
  
  [DebuggerDisplay("Name = {Name}")]
  public class Person
  {
      public string Name;
  }
  </code></pre>
  
  <p>or </p>
  
  <pre><code>public class Person
  {
      public string Name;
      public override string ToString()
      {
          return string.Format("Name = {0}", Name);
      }
  }
  </code></pre>
  
  <p>Is there any reason to prefer one to the other? Any reason not to do both? Is it purely personal preference?</p>