-
In Windows XP and Vista the algorithm used to sort files by name in Explorer does not simply compare the strings alphabetically, but has additional logic such as treating numeric characters as numbers. This means that a file named "20.txt" appears after "3.txt" in Explorer, even though...
-
C# does not automatically curry functions, so a function that multiplies two double s together and returns the result must be assigned to a delegate that takes two arguments and returns a result: Func < double , double , double > multiply = (a, b) => a * b; This seems reasonable, but unfortunately...
-
After my post about deferred execution semantics and re-entrancy I've had a couple of people ask why iterator code has deferred execution semantics rather than just executing immediately. To understand this we need to see how iterators are actually implemented. Consider the following very simple...
-
I've been a bit too busy with work and other things to finish the Linq translation posts, though I will return to them when I get some free time. For now I'll post some other things I had already drafted, and which are probably more interesting to most people anyway. Last year I noted that most...
-
This is the fourth entry in a series demonstrating how C# 3.0 query syntax is translated into the underlying method calls for Linq-to-Objects, and that you can write your own versions of the Linq extension methods. The previous entries were: Part 1: Introduction and Select Part 2: SelectMany Part 3:...
-
This is the third entry in a series demonstrating how C# 3.0 query syntax is translated into the underlying method calls for Linq-to-Objects, and that you can write your own versions of the Linq extension methods. The previous entries were: Part 1: Introduction and Select Part 2: SelectMany Now we know...
-
This is the second entry in a series demonstrating how C# 3.0 query syntax is translated into the underlying method calls for Linq-to-Objects, and that you can write your own versions of the Linq extension methods. In the first entry I outlined the types and collections I'd be using for this series...
-
The Linq query syntax introduced in C# 3.0 is an extremely powerful way to manipulate collections of objects. Depending on the query provider the expression may be translated in a number of ways, such as SQL statements for Linq-to-SQL or XQuery expressions for Linq-to-XML , but the simplest is when you're...
-
The introduction of the var keyword in C# 3.0 was required to support anonymous types, however it may also be used to declare variables for named types. This seems to have sparked quite a lot of debate about where the use of var is appropriate. The C# Reference documentation page (linked previously)...
-
If you create a method to return a random set of items from an enumerable list, implemented using an iterator... public static IEnumerable<T> GetRandom<T>(this IEnumerable<T> items) { var random = new Random(); foreach (var item in items) { if (random.Next() < 0.5) { yield return...
-
Jeff Atwood has quite a number of posts comparing VB and C#, and the general theme is the claim that the verbosity of VB makes it easier to read . One aspect he doesn't appear to have considered, however, is the information redundancy caused by Visual Basic's verbose syntax. Consider the following...
-
To get a better understanding of how Lambda functions - and the functional programming capabilities they imply - might be used in C# 3.0, I've started playing around with Scheme (an introductory set of video lectures from MIT are available free to download ). One commonly used functional paradigm...
-
I was bored this weekend so I ended up trawling through a bunch of blog archives and came across posts from some well respected people about why they believe Hungarian notation (in its originally intended form) is a good thing. There are entries from Eric Lippert , Joel Spolsky and Larry Osterman which...
-
Recently I was working on a simple message receiver from MSMQ queues. The MessageQueue.Peek() method is pretty poorly designed as instead of returning a Boolean or null when there is no message on the queue, it throws a MessageQueueException with the MessageQueueErrorCode set to IOTimeout. Why is this...