porges

Category: code

Objects can be collected while their instance methods are still executing

In Peter Ritchie’s post Dispose Pattern and “Set large fields to null”, he states the following (my highlighting): At face value, setting a field to null means that the referenced object is now unrooted from the class that owns the field and, if that was the last root of that reference, the Garbage Collector (GC) [...]

On i, j, … as iteration variables (but really a foray into primary sources)

This question was recently asked on StackOverflow: I know this might seem like an absolutely silly question to ask, yet I am too curious not to ask… Why did “i” and “j” become THE variables to use as counters in most control structures? The question has generated many answers, from scholarly to spurious — but [...]

Casting in .NET via object mutation

In this post, we will see how to make the following code fail: object it = new SomeStruct { Item = 1 };   Floatsy(it);   Console.WriteLine(((SomeStruct)it).Item); At runtime, it will throw an InvalidCastException!

Validating email addresses with .NET regex

I did validation in Haskell a while back, and since I recently discovered .NET’s “balancing groups” regex feature, it seems like it would be a good time to do it for .NET.