Home c# Simple / primitive / built-in types in C #

Simple / primitive / built-in types in C #




Hello! Please give me a definition of the following concepts:

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

And what types belong to these groups.

Why am I interested – read Richter’s book “CLR via C #”, namely Chapter 5, see the table of primitive types, which are written:

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

But, then Richter already wrote that the decimal is not primitive. A contradiction.
I then climbed in MSDN library and found the following:

  1. For simple types are: The numeric types and bool ;
  2. For a built-in types are: The numeric types ; bool ; string ; object .
  3. For primitive types include: All numeric types (except decimal ); bool ;
    IntPtr ; UIntPtr .

Links: 1 and 2 point ; 3 point .

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

I was looking for other sources: there are simple / primitive / built-in types – are synonymous


Answer 1, Authority 100%

The canonical source of information – official language specification. It states (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 is a string , object and dynamic is not simple-type . The same list is given in an explicit form in Section 4.1.4: sbyte , byte , short , ushort , int , uint , long , ulong , char , float , double , bool , decimal .

The word “primitive” is used in the specification only twice: 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 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.

is nowhere more precise definition, so we can assume that the concept of primitive type is not formalized. The same applies to the built-in : This term is not found in the specification


Richter, apparently, allows himself a few free treatment with the terms (it is so steep that can afford it).

Answer 2, Authority 15%

So how may still be questions, I will try to answer yet.
If once, then:

  1. Built-in (predefined) types:
    • The types of values:
      • The numeric types (all):
        • A signed integer (sbyte, short, int, long)
        • An unsigned integer (byte, ushort, uint, ulong)
        • IEEE floating point representation (float, double)
        • Extended-precision decimal
      • Boolean type (bool)
      • Unicode characters (char)
    • Reference types:
      • Unicode strings
      • Base class for all types (object)
  2. Simple types:
    • Numeric types (all):
      • Signed integers (sbyte, short, int, long)
      • Unsigned integers (byte, ushort, uint, ulong)
      • IEEE floating point representation (float, double)
      • Extended-precision decimal
    • Boolean type (bool)
    • Unicode characters (char)
  3. Primitive types:
    • Numeric types (no decimal):
      • Signed integers (sbyte, short, int, long)
      • Unsigned integers (byte, ushort, uint, ulong)
      • IEEE floating point representation (float, double)
    • Boolean type (bool)
    • Unicode characters (char)
    • System.IntPtr
    • System.UintPtr

Exact definitions:

  1. C # predefined types are aliases for .NET Framework types in the System. The two operators shown below differ only in syntax:

    int i = 5;
    System.Int32 i = 5;
  2. Simple types are built-in value types.

  3. The set of predefined value types other than decimal are known in the CLR as primitive types. Primitive types are so named because they are supported directly through instructions in the compiled code, which are usually translated into direct support within the available processor. For example:

    // Underlying hexadecimal representations
    int i = 7; // Oh7
    bool b = true; // Ox1
    char c = 'A'; // Oh41
    float f = 0.5f; // Uses IEEE floating point encoding

    The types System. IntPtr and System. UintPtr are also primitive.


C # 6.0. Directory. Full description of the language. p.56

https: / /docs.microsoft.com/ru-ru/dotnet/csharp/language-reference/keywords/built-in-types-table

https://msdn.microsoft.com/en -ru / library / system.type.isprimitive.aspx

https: // docs .microsoft.com / ru-ru / dotnet / csharp / tour-of-csharp / types-and-variables

https://www.microsoft.com/en -us / download / details.aspx? id = 7029

Answer 3

I think the primitive type definition should look something like this:

A primitive type is a noncomplex data type, that is, types such as int, double, boolean, single, byte, etc., occupying a strictly defined number of bytes in memory. String, Object. enum is no longer primitive, but composite data types, that is, consisting of a number of primitives. For example, string, in addition to a set of characters and a pointer to the first character, stores at least its own length in memory.

Answer 4

There are two main data types in C #: value types and reference types. They differ in the content of the variable. Variables of a value type contain the value itself. And variables of a reference type contain a reference to an object.

Numeric types and bool are considered simple (and sometimes called primitive, as in Schildt’s textbook) simply because their variables hold a value rather than refer to anything + they are the lowest-level data items.

Answer 5

decimal by definition can not be a simple type due to its structure, there at least 2 parts are there.
There are ChPZ – Real, Float, Double
Integer – Char, Byte, int
That’s all.
bool can also be simple type, for the concept of true / false is not numerical (unlike C / C++ where it can be defined through #define ) But in many languages it is a built-in type.
In the context of C #, it is possible to talk about simple types in general, only with a large stretch is a typed language.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions