Iterating over a Generic Dictionary

It can be tedious to iterate over a generic Dictionary in C#, especially if the Dictionary contains complex types. The values you’re interested in are properties of the iteration variable. I never know what to name the iteration variable (here I name it “pair”), which is an indicator this code is clumsy. Make it easier on yourself by using C#’s Tuple Deconstruction language feature. First, write an extension method for the generic KeyValuePair class. Or, instead of writing the extension method, you can add a reference to my ErikTheCoder.ServiceContract package and add a using ErikTheCoder.ServiceContract; statement. Then rewrite your foreach […]

Launching My Programming Blog

I’ve decided to start a blog devoted to programming topics. I’ve been writing code since I was nine years old, when my father bought an Apple IIe computer and I discovered it could be made to perform tasks using a language named “Basic.” I’m now 44 years old, so this blog is way overdue. My feelings of delinquency (how have I not started this yet?), along with reasons stated in the sidebar to the right (below on a phone), are the impetus for me to blog about software and the joy of programming. In addition to writing code, I will […]