Is String a primitive type?

后端 未结 10 1189
难免孤独
难免孤独 2020-11-27 18:36

I am curious about the string and primitive types. Article like this says string is primitive type. However second article on MSDN does not list string as primitive type.

10条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-27 18:37

    In c# the types are primarily defined as two types: value types and primitive types.

    First see the definition of primitive types in C#.

    On the other hand, all primitive data types in C# are objects in the System namespace. For each data type, a short name, or alias, is provided. For instance, int is the short name for System.Int32 and double is the short form of System.Double.

    Now, read this article for the difference: Primitive Types & Value Types

    System.String maps to "string", which is a primitive type in the CLI. But in the reality, value types are the ones which go in the stack and not in the heap space.

    So, the key is Value types vs Primitive types. By Microsoft's definition of primitive, it is a primitive type, but in a more general sense, its not.

提交回复
热议问题