Tag Archives: Tips

Timing a Method in C#

Here’s a very quick way to check the performance of a block of code. I’m wrapping a System.Diagnostics.Stopwatch class and sending all timings directly to Debug.WriteLine(). Please be aware that this is a very simplistic approach, and does not guarantee … Continue reading

Posted in Tips and Tricks | Tagged , | 2 Comments

Using Shapes as a Resource in WPF

This post covers how to re-use a collection of WPF shapes by combining them into a resource. Start by creating the drawing using Expression Blend. This example using a combination of Ellipses, Rectangles and Paths to create the rounded triangle: … Continue reading

Posted in Tips and Tricks | Tagged , , | 1 Comment

Switch Statement Code Snippet

Another Visual Studio tip – a colleague of mine showed me the “switch” code snippet. It automatically builds a complete switch statement with a case for each value in an enumeration. This can really save some time. Here’s an example: … Continue reading

Posted in Tips and Tricks | Tagged , , | 1 Comment

Detecting the Debugger

I’ve just discovered that .NET has a very quick way to detect when the debugger is attached. This has been so handy the past few days, and it works both for WinForms and ASP.NET…

Posted in Tips and Tricks | Tagged , | Leave a comment

ASP.NET Register User Controls Globally

If you drag a user control onto a web page in design view, Visual Studio automatically adds a Register tag at the top of the page: This is fine if you only have a few controls on a couple of … Continue reading

Posted in Tips and Tricks | Tagged , | Leave a comment

XmlDocument: A Simple Example

The XmlDocument class contains everything we need to build an XML document from scratch. The syntax can be tricky if you haven’t used the class before, so this post will hopefully serve as a quick how-to guide. We’re going to … Continue reading

Posted in Reference | Tagged , , | Leave a comment

C# Null-Coalescing Operator

The ?? operator allows you to specify a default value when a nullable type is assigned to a non-nullable type. Let’s define a nullable int, using the Nullable shorthand: By using the ?? operator we can assign x to y … Continue reading

Posted in Tips and Tricks | Tagged , | Leave a comment