Local functions in C# (aka nested methods)

C# 7 introduced a new tool for the belt - local functions. Let’s take a look at what they are, how to use them, and why we might not want to.

  Oct 8, 2022 (rev. Oct 11, 2025) ·  6 min

Checking for null in C#, using the null conditional and null coalescing operators

Checking for nulls in C# is tedious, but C# 6 gave us the null-conditional operator. Let’s see what we can do with it!

  Sep 27, 2022 (rev. Dec 3, 2025) ·  6 min

Using string interpolation to craft readable strings in C#

The longer I write software, the more I come to appreciate clear code. String interpolation in C# is just one more way to help us do that.

  Sep 19, 2022 (rev. Oct 11, 2025) ·  4 min

Mocking MessageBox (or any static class) in WinForms

Unit testing a WinForms app is an uphill battle in the best of times, before you add in classes like MessageBox. Let’s make the best of it.

  Jan 7, 2022 (rev. Oct 11, 2025) ·  4 min

Using nameof to avoid magic strings in C#

There’s a lot of ways to make our code work for us. Let’s check out using the nameof operator to avoid magic strings.

  Dec 30, 2021 (rev. Nov 27, 2025) ·  6 min

Using Async, Await, and Task to keep the WinForms UI responsive

Using the async/await pattern in WinForms is an easy win, helping prevent one of the most annoying user experiences - a frozen UI.

  Jun 7, 2021 (rev. Oct 11, 2025) ·  8 min

The right way to rethrow an exception in C#

All programming languages have gotchas to trip you up, and C# is no exception. Today, let’s check out the subtle (but significant) difference between “throw” and “throw ex”.

  Sep 17, 2020 (rev. Oct 11, 2025) ·  4 min

Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement

This error might look a little cryptic at first glance, but it’s fairly descriptive in explaining what’s wrong. You’re likely to come across this one before your first cup of coffee.

  Nov 14, 2019 (rev. Oct 11, 2025) ·  2 min

Assign C# code to a variable and then run it

Did you know most languages have a way to pass around code to other functions, so you can call (invoke) it in other parts of your application? In C#, it’s called a delegate.

  Nov 13, 2019 (rev. Oct 11, 2025) ·  3 min

How can I find the state of NumLock, CapsLock or ScrollLock in WPF?

If you’re writing a WPF application and need to find the state of the Num Lock, Caps Lock, or Scroll Lock keys, you’re in luck - there’s a method for that.

  Nov 12, 2019 (rev. Oct 11, 2025) ·  1 min