Question

The enum System.TypeCode is defined as follows:

public enum TypeCode
{
   Empty = 0,
   Object = 1,
   DBNull = 2,
   Boolean = 3,
   Char = 4,
   SByte = 5,
   Byte = 6,
   Int16 = 7,
   UInt16 = 8,
   Int32 = 9,
   UInt32 = 10,
   Int64 = 11,
   UInt64 = 12,
   Single = 13,
   Double = 14,
   Decimal = 15,
   DateTime = 16,
   String = 18,
}

Out of curiosity, what happened to TypeCode of value 17? Has it ever existed? Why has TypeCode.String the value of 18 and not 17?

Was it helpful?

Solution

The following blog post explains the hole:

This is a good question. I was digging through the history of this file to see if I could figure out what happened, and it’s not clear. We’ve had this “hole” in the TypeCode enum since October of 2000, and I can’t find an older set of bits. But, I’m sure that comment in IConvertible is right – this used to be TimeSpan. For TimeSpan, it’s possible we thought it would be interesting for a while, then we realized that frankly not that many people need to convert a Decimal to a TimeSpan, then removed it.

You might ask why we didn’t “fix” the enum when we removed whichever of these values we had originally added. It turns out that whenever we have a breaking change internally, we need to recompile all the code that might possibly depend on the removed or changed public surface area. For us, that would mean rebuilding everything that might have referred to TypeCode.String, whose value would have changed from 18 to 17. While we do go through that process internally in DevDiv, it is costly & painful for us.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top