I was working with a client recently when I encountered a completely unexpected bug. Figuring out the problem reminded me of some facts about how C# (and all the .NET languages) work and got me thinking about the fact that object-type variables in .NET are basically pointers, even though it’s hidden from you most of the time.

The Problem

An object instance was passed into a method. If the parameter was not null, it was simply updated, but if the parameter was null, then it was instantiated first, then updated.

It looked something like this:

class Widget
{
    public...