Objects can be collected while their instance methods are still executing

code 3 May 2012 | 0 Comments

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) [...]

Tagged in , ,

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

code 10 January 2012 | 0 Comments

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 [...]

Tagged in , ,

Casting in .NET via object mutation

code 13 May 2011 | 0 Comments

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!

Tagged in , , , ,

Validating email addresses with .NET regex

code 10 May 2011 | 0 Comments

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.

Tagged in , , , ,