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. Sep 16, 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. Sep 16, 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. Sep 16, 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. Sep 16, 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. Sep 16, 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. Sep 16, 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. Sep 16, 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. Sep 16, 2025) ·  1 min

What is the opposite of Any in LINQ?

One of the many nice functions in LINQ is a single word that iterates through a collection, returning true if at least one item in the collection matches the condition you specify. But what’s the opposite of the Any keyword in LINQ?

  Nov 11, 2019 (rev. Sep 16, 2025) ·  2 min

Using an application config file with a .NET Standard app and NUnit 3

Porting .NET Framework code to .NET Standard has been a learning experience, with some challenges too. This time I had a .NET Standard library that expected an application config file, but loading one from an NUnit test suite proved to be more difficult than it sounded at first.

  Apr 15, 2019 (rev. Sep 16, 2025) ·  6 min