I have heard both "fundamental types" and "primitive types" being used.

Is there a difference in what the two phrases are referring to?

有帮助吗?

解决方案

Having followed the provided links leading to Microsoft documentation and having chewed on the words for a while, this is what I make of it.

Fundamental means machine architecture bound. So anything that fits the data directly handled by the hardware in the CPU is fundamental. It makes sense, doesn't it?

Primitive means language bound. The basic types directly supported by the language without the need to write a class or struct. Note that this includes string. They are the dark blue keywords in C#.

https://msdn.microsoft.com/en-us/library/aa711900(v=vs.71).aspx

其他提示

These terms are confusing and I would avoid using them in a formal setting without a specific definition.

In particular, I note that some editions of the C# specification uses the expression "primitive type" only twice, without definition, and somewhat inconsistently. It implies both that "primitive type" means "built in value types" and "any value type".

As David's comment notes, this is at odds with the definition of "primitive type" given in the .NET specification.

Rather than try to come up with a definition of "primitive", instead concentrate on clearly stating the property you would like a given set of types to have. Primitive types are often used to mean:

  • Types which are the atoms of a type system; that is, the types which are not themselves built from application of rules to other types.
  • Types which are provided for you by default in a language.
  • Types which are guaranteed by convention to be available in compliant languages.
  • And so on.

I would assume there is no difference in terms of meaning. However, a Google search highlights the "fundamental type" keyword in relation to Microsoft, .Net and C++ which suggests it is preferred instead of "primitive type" within those circles.

许可以下: CC-BY-SA归因
scroll top