Ben Griswold on June 10th, 2008

The following code throws an InvalidCastException.
public static MachineProductCollection MachineProductsForMachine(
MachineProductCollection MachineProductList, int MachineID)
{
return (MachineProductCollection)
MachineProductList.FindAll(c => c.MachineID == MachineID);
}

This surprises me since MachineProductCollection is merely a generic List of MachineProducts which is exactly FindAll() returns.  Here’s the full MachineProductCollection source code:
[Serializable]
public [...]

Continue reading about InvalidCastException Though Same Base Class

Ben Griswold on September 7th, 2007

We ran into the following issue two days ago.  In a nutshell, the “initialCategory” was not being selected in the Categories dropdown by default.  Yes, I recognize that the code itself may be written in fewer lines, but please only focus on the differences between the two code snippets below.  I haven’t had the time to [...]

Continue reading about C# Brain Scratcher of the Day

Ben Griswold on January 24th, 2007

If you like to drive your fellow developers mad, here’s something fun.  The next time you need to manage a bunch of dates, add them to a Hashtable AFTER converting ToString().  For example,

DateTime holiday = new DateTime(2007,1,1); Hashtable htHolidays = new Hashtable(); htHolidays.Add(holiday.ToString(), holiday.ToString()); …

Next, create a function similar to the following:

public static bool isHoliday(string [...]

Continue reading about January First is Not a Holiday

Ben Griswold on November 15th, 2006

I picked up a new development box the other day and I spent most of yesterday (heck, it was ALL of yesterday) getting the machine configured. Nearly all software installed without any issues except for SQL Server 2005 Developer Edition. After completing the installation, I planned to validate the installation by first checking to see [...]

Continue reading about SQL 2005 Installation Issues … Again