来自 C# 5.0 规范
4.4 Constructed types
A generic type declaration, by itself, denotes an unbound generic type that is used as a “blueprint” to form many different types, by way of applying type arguments. The type arguments are written within angle brackets (< and >) immediately following the name of the generic type. An unbound generic type can only be used within a typeof-expression (§7.6.11). A type that includes at least one type argument is called a constructed type. A constructed type can be used in most places in the language in which a type name can appear. An unbound generic type can only be used within a typeof-expression (§7.6.11).
Constructed types can also be used in expressions as simple names (§7.6.2) or when accessing a member (§7.6.4).
“构造类型”的概念与“有界泛型”的概念相同吗?
4.4.3 Bound and unbound types
The term unbound type refers to a non-generic type or an unbound generic type. The term bound type refers to a non-generic type or a constructed type.
An unbound type refers to the entity declared by a type declaration. An unbound generic type is not itself a type, and cannot be used as the type of a variable, argument or return value, or as a base type. The only construct in which an unbound generic type can be referenced is the typeof expression (§7.6.11).
非泛型类型既是未绑定(bind)类型又是绑定(bind)类型吗?
最佳答案
Is the concept of "constructed type" the same as the concept of "bounded generic type"?
是的,模数你的错字。您的意思是说“绑定(bind)泛型类型”,而不是“绑定(bind)泛型类型”。
Is a non-generic type both an unbound and bound type?
是的。
Why are the terms so redundant/duplicate/convoluted?
这些术语是为了方便规范作者和编译器团队而发明的。您发现的唯一冗余是constructed 等于bound generic,这对我来说似乎很合理。我没有看到任何重复或卷积。
如果这些术语看起来很复杂,那么我向您提出,现代业务线 OO 语言的类型理论是一个复杂的主题;它的行话反射(reflect)了这种复杂性。
这样想可能会有所帮助。假设我们有一个 C 类,它接受 n 个类型参数,对于 n >= 0:
- 概念 C-that-takes-n-type-arguments 是一个未绑定(bind)类型。
- 概念 C-with-n-type-arguments 是一个绑定(bind)类型。
- 绑定(bind)的泛型类型必须是用类型参数构造的泛型类型,所以我们称它为构造类型。
显然,如果 n == 0,则 C 同时是绑定(bind)类型和未绑定(bind)类型。
关于c# - 构造类型、有界类型和无界类型的含义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43646302/