typeof(decimal).IsPrimitive == False Bug or Feature?

  • Thread starter Thread starter Carl Rosenberger
  • Start date Start date
C

Carl Rosenberger

Hi all,

I find it quite surprising that the System.Decimal Type
is not a primitive data type.

Is this on purpose?
Why?

Kind regards,
Carl
 
Carl Rosenberger said:
I find it quite surprising that the System.Decimal Type
is not a primitive data type.

Is this on purpose?
Absolutely.

Why?

Because it's not a primitive type. From Type.IsPrimitive:

"The primitive types are Boolean, Byte, SByte, Int16, UInt16, Int32,
UInt32, Int64, UInt64, Char, Double, and Single."

The CLR doesn't need to have any intrinsic knowledge about the decimal
type - it treats it just as another value type which happens to have
overloaded operators. There are no IL instructions to operate directly
on decimals, for instance.
 
Carl,

I would think that it is because it can be reduced into other, smaller
parts. From the description, the Decimal structure really is made up of
other primitive types, so I can see why IsPrimitive would return false.

Hope this helps.
 
Back
Top