In C# are the terms “Primitive” and “Literal” interchangeable?

前端 未结 8 766
[愿得一人]
[愿得一人] 2021-02-07 20:43

A discussion earlier today led me to question whether or not my understanding of primtives and literals is correct.


My understanding is that a literal type is spec

8条回答
  •  时光取名叫无心
    2021-02-07 21:20

    I just wanted to inject a quick note here.

    The C# language specification clearly defines "literal" -- a literal is a source code representation of a value. Literals are things like true, 10, 5.7, 'c', "hello" and null -- they are text that represents a specific value.

    The C# language specification uses the word "primitive" twice; it is never defined and completely vague as to what it could possibly mean.

    The C# language spec has no need to use or define the word "primitive" and therefore should not make use of this vague term. I've had a talk with Mads and we've agreed that future editions of the spec will be reworded to eliminate this usage completely.

    How other type systems specifications -- the reflection library, the CLI, the VES, and so on -- define the word "primitive" is of course up to them.

    Thanks for bringing up the question.

提交回复
热议问题