c# - 构造类型、有界类型和无界类型的含义?

标签 c# visual-studio

来自 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/

相关文章:

c# - 1对1的关系

c# - assembly 中的类型是使用旧版本的 blend sdk 构建的,在 Windows presentation Foundation 4 项目中不受支持

c++ - 如何在 Visual Studio 中调试命令行实用程序

visual-studio - 如何重新开启代码审查?

c# - 不允许 JSONP WCF 方法

c# - EFCore 删除引用的实体

.net - 删除未使用的引用(!= "using")

database - Entity Framework 代码优先迁移类文件

c# - 代码优先与数据库优先

c# - 从共享文件夹启动 .NET 控制台应用程序时禁用 "The publisher could not be verified"