Rant of the day: IDisposable

My colleagues are probably used to the fact that I rant about code quality frequently. I take code quality very seriously. Not because I’m especially expert in it, but because features of basic code quality make it easier for other people to read and maintain the code. Today’s irritation comes from some code (replicated in […]

The StackOverflowException

Take a look at the following code: class Program { static void Main(string[] args) { try { RecurseForever(); } catch (StackOverflowException) { Console.WriteLine(“Caught Stack Overflow Exception”); } catch (Exception) { Console.WriteLine(“Caught general Exception”); } Console.ReadLine(); } static void RecurseForever() { RecurseForever(); } } What do you think the output of the program will be? If […]

Formatting dates the hard way

I was doing a bit of a code review and I spotted this in the code base. string[] splitOptions = new string[1] { dayEarlier.Date.Year.ToString() }; string[] earlyDates = dayEarlier.Date.GetDateTimeFormats(); string[] earlySplit = earlyDates[67].Split(splitOptions, StringSplitOptions.RemoveEmptyEntries); earlySplit[0] = earlySplit[0].Replace(“,”, string.Empty); Essentially the code gets the date in a specific format. However, it does it in the oddest […]

Tip of the Day #8 (string performance)

Concatenating strings in .NET can be very easy. There is the overloaded + operator that makes stringA + stringB + stringC statements very easy to write. But, it isn’t very performant. The reason is that strings are immutable, and concatenating strings in this way causes lots of short-lived objects to be created and thrown away, […]

Monitoring change in XML data (LINQ to XML series – Part 5)

This is the 5th part in a series on LINQ to XML. In this instalment we will look at monitoring changes in XML data in the XML classes added to .NET 3.5. The XObject class (from which XElement and XAttribute, among others) contains two events that are of interest to anyone wanting to know about […]

Tip of the Day #4 (Connection Strings in Config files)

From .NET 2.0 onwards a new and improved configuration management system has been put in place. You can now add a <connectionString> element to the config file and use it to place the connection strings to the database and then retrieve then in a consistent way in your application. It supports multiple connection strings too […]