DebuggerDisplayAttribute or ToString() to help debugging

[DebuggerDisplay("Customer={CustomerName} Phone={CustomerPhone}")]
class WEOTestClass
{
    public WEOTestClass(string _name, string _phone)
    {
        CustomerName = _name;
        CustomerPhone = _phone;
    }

    public string CustomerName { get; set; } 
    public string CustomerPhone { get; set; }

    public override string ToString()
    {
        return( "Customer: " + CustomerName + " Phone: " + CustomerPhone );
    }
}

For viewing classes when debugging in the Visual Studio IDE, both DebuggerDisplay and a ToString() work well.  While ToString() is more typing, it has the added benefit when logging to files or other output (besides the debugger).

Leave a Reply

Your email address will not be published. Required fields are marked *