There are some nice things to know about Visual Studio.Net 2008 that can make life easier as a programmer. In the series ‘Debugger tips VS.Net’ I am gonna talk about the debug techniques VS.Net 2008 offers. Tracepoints is the subject of this post. A tracepoint is a breakpoint with a custom action associated with it. When the tracepoint is hit the custom action is performed. An example of such a action is writing a traceline to the output window.

How can you add a tracepoint? This is easy: go to the line of code where you want the tracepoint and press F9. This will add a breakpoint. The picture below shows a breakpoint.

 

Then right click the breakpoint and choose When hit from the menu that appears.

 

The When Breakpoint Is Hit dialog appears. In this dialog you can choose to print a message. This will add tracelines to the ouput window every time the tracepoint is hit. The message can be formatted and You can include programmatic information using DebuggerDisplayAttribute syntax. You can choose to run a macro when the tracepoint hits too. In the screenshot below the DumpStacks macro from the samples is picked. Select Continue Execution if you don’t want the tracepoint to break execution of your program.

 

 A tracepoint has its own icon. It is a red diamond in the margin of the code edit window.

 That was it.

kick it on DotNetKicks.com

 Software development is an art.

The ?? operator C# operator returns the left side if it is not null. It returns the right side if the left side is null. It is very handy in situations where you can expect a value to be null but you want to use a default value if it is. Here is an example:

        <span style="color: #0000ff">string</span> valueCouldBeNull = GetTheValue() ?? "<span style="color: #8b0000">The default value</span>";
        Console.WriteLine("<span style="color: #8b0000">The result is </span>" + valueCouldBeNull);
&#160;

When assigning nullable types to non-nullable types you can avoid compile-time exceptions using the ?? operator.

kick it on DotNetKicks.com