Is String a primitive type?

后端 未结 10 1224
难免孤独
难免孤独 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 19:03

    String is a special primitive type. It is not a value type, but can be considered a primitive type because it can be created by writing literals, eg/ "hello" and it is possible to declare a constant of type string. Having said that, the value of IsPrimitive returns false

    Console.WriteLine("hello".GetType().IsPrimitive) // output = False
    

    EDIT: I want to take back my answer here. It is technically not a primitive type, but shares the properties I stated above.

提交回复
热议问题