As you know, MSDN library says that string
, decimal
and object
are not primitive types. I'm sharing a quote about this:
The primitive types are Boolean, Byte, SByte, Int16, UInt16, Int32, UInt32, Int64, UInt64, IntPtr, UIntPtr, Char, Double, and Single.
We can test it also by typeof(typeName).IsPrimitive
property. An addition, I read discussions about string
type on stackoverflow.com too.
Nowadays I am reading a book as named CLR via C# (Fourth Edition) and this book says that (on page 112):
As you see, the writer(Jeffrey Richter) mentions that all these are primitive types.
So, can anyone clarify me, what does he mean? Why these string
, decimal
, object
, and dynamic
types are in primitives list?
I wouldn't personally call dynamic
, decimal
, object
or string
primitive types. I'd use Type.IsPrimitive
for the canonical source there. Note that dynamic
isn't even a type in the CLR sense.
The C# 5 MS specification only uses the word "primitive" twice - once in the introduction and once in quotes. The upcoming ECMA C# 5 standard doesn't use it at all. Given that the term "primitive" is well-defined for CLR types and isn't part of standardized terminology for C#, it seems like a bad idea to use it in this way. (There are places where the C# spec and the CLR disagree, e.g. on what conversions are available, whether structs have parameterless constructors etc. That's slightly different and more awkward.)
In standard C# terminology, there are simple types - but those are only the value types for which there are keywords.
I can't see any term in the C# 5 MS specification or the ECMA standard which describes "the keywords describing types".
See more on this question at Stackoverflow