How to use DebuggerDisplayAttribute in C# and VB.NET

If you want to change the information, the debugger variable window shows for your class, you can use the DebuggerDisplayAttribute.
Simply put the Attribut above your class declaration. The Value between {} are the name of the property or Field you want to show.

Sample C#

[DebuggerDisplay("Name = {Name}, Value = {Value}")]

Sample VB.NET

<DebuggerDisplay("Name = {Name}, Value = {Value}")>

Result

DebuggerDisplayAttribute

for more informations see the DebuggerDisplayAttribute Class MSDN Entry

How to use the DebuggerDisplay Attribut

You can use the DebuggerDisplay Attribut like in the sample shown below.

Sample C#

class Program
    {
        static void Main(string[] args)
        {
            var myPlayer = new Player
            {
                Firstname = "John", 
                Lastname = "Doe", 
                CreationDate = DateTime.Now, 
                Points = 9999
            };
            Console.WriteLine("Firstname={0}, Lastname={1}, Points={2}, CreationDate={3}", myPlayer.Firstname, myPlayer.Lastname, myPlayer.Points, myPlayer.CreationDate);
        }

        [DebuggerDisplay("Firstname={Firstname}, Lastname={Lastname}, Points={Points}, CreationDate={CreationDate}")]
        public class Player
        {
            public string Firstname { get; set; }
            public string Lastname { get; set; }
            public long Points { get; set; }
            public DateTime CreationDate { get; set; }
        }

    }

Sample VB.NET

Sub Main(args As String())
        Dim myPlayer = New Player() With { _
            .Firstname = "John", _
            .Lastname = "Doe", _
            .CreationDate = DateTime.Now, _
            .Points = 9999 _
        }
        Console.WriteLine("Firstname={0}, Lastname={1}, Points={2}, CreationDate={3}", myPlayer.Firstname, myPlayer.Lastname, myPlayer.Points, myPlayer.CreationDate)
    End Sub

    <DebuggerDisplay("Firstname={Firstname}, Lastname={Lastname}, Points={Points}, CreationDate={CreationDate}")> _
    Public Class Player
        Public Property Firstname() As String
            Get
                Return m_Firstname
            End Get
            Set(value As String)
                m_Firstname = Value
            End Set
        End Property
        Private m_Firstname As String
        Public Property Lastname() As String
            Get
                Return m_Lastname
            End Get
            Set(value As String)
                m_Lastname = Value
            End Set
        End Property
        Private m_Lastname As String
        Public Property Points() As Long
            Get
                Return m_Points
            End Get
            Set(value As Long)
                m_Points = Value
            End Set
        End Property
        Private m_Points As Long
        Public Property CreationDate() As DateTime
            Get
                Return m_CreationDate
            End Get
            Set(value As DateTime)
                m_CreationDate = Value
            End Set
        End Property
        Private m_CreationDate As DateTime
    End Class

Result

it will be shown like this when debugging.

DebuggerDisplay

for more informations see the MSDN Using DebuggerDisplay Attribute