object.Equals handles null values correctly

code 28 March 2008 | 0 Comments

Here’s the source code, as disassembled by Reflector: public static bool Equals(object objA, object objB) { return ((objA == objB) || (((objA != null) && (objB != null)) && objA.Equals(objB))); } It seems that not even Microsoft knows this! I spotted this code, from ASP.NET’s MVC implementation, on Scott Hanselman’s blog: return (other != null) [...]

Tagged in , , ,

A simple BigNum library for .NET

code 13 October 2007 | 7 Comments

Update Due to minor demand, the code is also available: BigNum source. Please note that I haven’t actually touched the code since it was first written. I’m sure there’s some things that don’t work properly. If you’re doing anything big with this you probably want to write some ‘destructive’ update functions for adding, etc. At [...]

Tagged in , , , ,

Fun(c) with C# 3.0

Uncategorized 9 October 2007 | 1 Comment

Looking through the list of predefined (or, in Microsoft’s parlance, standard) query operators defined in C# 3.0, there is one that stands out as missing: the ‘map’ function. However, with the new query expression syntax, this is trivial to define: public static IEnumerable<T> Map<F,T>(Func<F,T> func, IEnumerable<F> source) { return from it in source select func(it); [...]

Tagged in , , , , ,

Lazy Lists in C#

Uncategorized 28 September 2007 | 0 Comments

I had the thought—while browsing through some old code—that the code I used to implement futures in C# would be useful for doing things lazily, if you just moved the evaluation phase to when the value was actually demanded… this started me off thinking about how to implement a proper lazily-evaluated list in C#. A [...]

Tagged in , , , ,