-
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...
-
On MSDN forums there was a question about whether class constructors should be permitted to do a lot of work or not : I have a dilemma and a dispute with some colleagues: should the constructor of a C# class do a lot or the minimum and latter in a method call put a lot of logic? I am coming from a C...
-
Conversion between primitive types is trivial in high-level languages like C# as you can use the cast operator, optionally surrounded with checked or unchecked to force the integer overflow semantics. At CIL level the conversion is less trivial, involving the choice of no fewer than 27 different op-codes...
-
Some languages such as C# let you treat the System.Decimal type as an integral type most of the time, even having the keyword decimal , and will let you declare constant fields of the type under some circumstances. However, decimal isn't a primitive type in the same way as the other numerics, and...
-
I don't know for sure, but my guess is because there are at least two implementations with different semantics: // immediate execution public static IEnumerable <T> ForEach<T>( this IEnumerable <T> source, Action <T> action) { foreach ( var item in source) { action(item);...
-
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...
-
Until now blinkBox has been using the ASP.NET in-process cache to handle all of our caching requirements, and it works very well for smaller sites, but as the number of users on the site increases it's rapidly becoming too small to hold all the data we want to keep cached. What we need is a distributed...
-
One thing that irritates me about software development is peoples apparent obsession with sub-namespaces called "Common" which they use to contain code that is used throughout the rest of the project/solution. Common namespaces are a code smell which often means you don't really understand...
-
Events in .NET are a fairly simple programming model - you subscribe to an event and when it is raised your handler is called. There are two common misconceptions about .NET events though. The first is that people believe event handlers are run in a multi-threaded manner, when in fact they aren't...
-
You might be wondering why I'm writing about the IDisposable interface a full five years after the .NET framework was released, when you'd think that everybody knows everything about disposing objects anyway. But there are many people who are new to the framework and need some guidance, and many...
-
I'm sick of the static vs instance methods argument based on performance. Performance has nothing to do with it. You should make your methods either static or instance depending on the way the method is used and what is more intuitive to the user of the class. Even Microsoft are guilty of pushing...
-
At first glance it seems simple to implement object equality in .NET, just override the Equals method inherited from System.Object, but in reality there actually are a lot of potential problems. You need to consider comparing null objects, and also the string representation, hash code and immutability...
-
Generics are by far my favourite addition to .NET in version 2.0 - not least because I never have to write a strong typed collection again! But uses for them crop up all over the place. Recently I've been implementing a lot of classes with singleton instances, such as in configuration handlers, which...