Consequences of array covariance in C#

Posted on Fri 22 October 2021 in Coding • Tagged with csharp, covariance, cast

In today’s post, I’ll talk about array covariance in C#, how it hid a bug in code that was covered by a passing unit test (*gasp*), and some ideas for how to avoid such bugs.

What is covariance?

In computer science, variance has to do with how complex …


Continue reading

Tricked by the IDE, broke the build

Posted on Tue 18 September 2012 in Coding • Tagged with fail, vb.net, csharp, vs2010

Over the last year, I’ve written a fair amount of Visual Basic .NET code for a customer project. As a result, I know a lot more VB.NET than I would like to, and I’ve run into a number of peculiar behaviors, such as this one. In this …


Continue reading

Regular expression multiline mode - what's a newline?

Posted on Wed 30 May 2012 in Coding • Tagged with newline, regular expressions, csharp, java

I stumbled upon an interesting little detail as I was using a regular expression in a unit test case in a C# application. I had a multiline string and was searching for a particular substring in multiline mode. The newlines in the string were Windows newlines, meaning CR followed by …


Continue reading

Strongly typed properties in Java vs C#

Posted on Thu 19 January 2012 in Coding • Tagged with delegate, generics, method group, csharp, java

The background for this post was that I needed to implement strongly typed properties in a C# project. With strongly typed property, I specifically mean a strongly typed version of public object GetProperty(string propertyName), where the property name is a constant (or name) of some sort, and the return …


Continue reading