c# – Simple / Primitive / Built-in Types in C #

Question:

Hello everyone! Please give definitions to the following concepts:

  1. Simple types (simple types);
  2. Primitive types (primitive types);
  3. Built -in types

And what types of these groups belong.


Why I was interested in this – while reading Richter's book "CLR via C #", namely Chapter 5, I see a table of primitive types, in which it is written:

  • Numeric types ( byte..double and decimal );
  • bool ;
  • string ;
  • object ;
  • dynamic .

But, further Richter already writes that decimal is not primitive. It turns out to be a contradiction. I then went into the MSDN library and found the following:

  1. Simple types include: Numeric types and bool ;
  2. Built-in types include: Numeric types ; bool ; string ; object .
  3. Primitive types include: All numeric types (except decimal ); bool ; IntPtr ; UIntPtr .

Links: 1 and 2 paragraph ; 3 pips

It turns out that Richter wanted to show built-in types in the table, but for some reason wrote them as primitive. Or am I missing something?

Looked in other sources: there simple / primitive / built-in types are synonyms.

Answer:

The canonical source of information is the official language specification . It says (section 4.1 Value types):

C # provides a set of predefined struct types called the simple types .

simple-type :

  • numeric-type
  • bool

numeric-type :

  • integral-type
  • floating-point-type
  • decimal

That is, decimal and bool are, but string , object and dynamic not simple-type . The same list is given explicitly in section 4.1.4: sbyte , byte , short , ushort , int , uint , long , ulong , char , float , double , bool , decimal .

The word “primitive” is used only twice in the specification: in Part 1 (Introduction):

C # has a unified type system . All C # types, including primitive types such as int and double , inherit from a single root object type.

and in part 11 (Structs):

Just as these predefined types are structs, it is also possible to use structs and operator overloading to implement new “primitive” types in the C # language.

Nowhere is there a more precise definition, so we can assume that the concept of primitive type is not formalized. The same applies to built-in : the term does not appear in the specification at all.

Richter, apparently, allows himself a somewhat libertine use of terms (he is so cool that he can afford it).

Scroll to Top