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...
There seem to be a lot of blog entries at the moment arguing over the relative merits of XML, JSON, YAML, S-Expressions, etc. as a data interchange format, and Web Services, WS-* Services and REST-style as the application protocol implementation. But while various articles make interesting academic points...
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...
From reviewing significant amounts of code over the last few years I have concluded that most people don't use Debug.Assert very much, if at all. I find this surprising because I use Debug.Assert a lot. Used prudently it can reduce bugs in code, make it more self documenting, and as an additional...
The short answer is to allow them to be handled differently in a programmatic manner. You've probably done it hundreds if not thousands of times - creating a try/catch block and catching an exception based on its type to handle it in a particular way. So the headline question in itself isn'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...
I always use stored procedures for data access because I believe that in a well designed system they are the most maintainable solution. However, I've been hearing a lot of support for inline SQL recently, so I figured it's time for an objective look at the advantages and disadvantages of each...
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...