.NET Tip of The Day
Learn one new .NET trick every day
Login or Join
.NET Tips & Tricks Community RSS

Those who prefer reading this site through RSS now can also subscribe for updates to .NET Tips & Tricks Community.

Use DebuggerStepThrough attribute to save time when debugging

When debugging code, one of the annoying things is to step into an one-line method or property. Assume that you have the following property:

    private string word;

    public string Word

    {

        get { return word; }

        set { word = value; }

    }

And you have a code that uses that property when calling a method:

    DoSomething(obj.Word);

When you debug that line, and hit F11 to step into the method, you'll step into the get section of the property, and only then move on to the method.

By placing System.Diagnostics.DebuggerStepThrough attribute above get and set sections of the property you instruct the debugger to step through that property and not into it:

    public string Word

    {

        [System.Diagnostics.DebuggerStepThrough]

        get { return word; }

 

        [System.Diagnostics.DebuggerStepThrough]

        set { word = value; }

    }

This instruction will cause the debugger not to step into method (property) as normal, but you can always place a breakpoint in that method and stop there.

8/30/2007
RSS .NET Tip of The Day
Subscribe to receive one tip from the .NET Tips and Tricks Community per day.
Previous Tips of The Day
The best of the .NET Tips & Tricks Community.
.NET Practitioners .NET Tips & Tricks Community
Every .NET practitioner has a trick up in their sleeve. This is the place to share it with other .NET people.
Submit a Tip
Discovered a new trick? Share it with others.
My Tips
Manage tips you authored.