简体   繁体   English

类型定义和类型引用之间有什么区别?

[英]What's the difference between type definition and type reference?

I am reading the book CLR via C# by Jeffrey Richter . 我正在阅读Jeffrey Richter CLR via C#书。

In Chapter 23(23.3.2) , it says "A System.Type object represents a type reference(as opposed to a type definition)." Chapter 23(23.3.2) ,它说"A System.Type object represents a type reference(as opposed to a type definition)."

What do the type reference and type definition mean here? 类型引用和类型定义在这里意味着什么?

The author is contrasting System.Type with System.TypeInfo . 作者将System.TypeSystem.TypeInfo对比。 From the documentation : 文档中

A TypeInfo object represents the type definition itself , whereas a Type object represents a reference to the type definition . TypeInfo对象表示类型定义本身 ,而Type对象表示对类型定义引用

The System.TypeInfo for a class can only be instantiated if the assembly that implements the class (the type definition) is loaded or loadable. 仅当实现类的程序集(类型定义)已加载或可加载时,才能实例化类的System.TypeInfo To instantiate a System.Type , the only requirement is that the current program contains a reference to the implementing assembly. 要实例化System.Type ,唯一的要求是当前程序包含对实现程序集的引用

See also What's the difference between Type and TypeInfo? 另请参阅Type和TypeInfo有什么区别?

A type definition happens when you define a new type through a class, a struct, an interface or an enum. 当您通过类,结构,接口或枚举定义新类型时,就会发生类型定义。

A type reference is a collection of information about a type, eg its name or its members. 类型引用是有关类型的信息的集合,例如类型名称或成员。

The System.Type class is able to represent a type, but not define a type. System.Type类能够表示类型,但不能定义类型。 When you call typeof(TypeName) or object.GetType() , you will deal with representations of types with objects of System.Type . 当调用typeof(TypeName)object.GetType() ,将使用System.Type对象处理类型的表示形式。

You can not directly instantiate an object of a type by just using a System.Type object. 您不能仅使用System.Type对象直接实例化类型的对象。 It only describes the type, but not is the type. 它只是描述的类型,但不能类型。 That's why it is called a reference. 这就是为什么它被称为参考。

A type definition implies the actual implementation of the type, such as, for example if it is a class, it means the definition of the class (with all its properties and fields). 类型定义表示类型的实际实现,例如,如果它是一个类,则表示该类的定义(及其所有属性和字段)。

A type reference , simply means that System.Type contains the details of a particular type, that is, it is the meta-data about the Type. 类型引用 ,仅表示System.Type包含特定类型的详细信息,即它是有关Type的元数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 基本引用类型与派生引用类型之间有什么区别 - What is the difference between base reference type vs derived reference type c#中的引用类型和值类型有什么区别? - What is the difference between a reference type and value type in c#? 复合类型和匿名类型之间有什么区别? - What's the difference between a compound type and an anonymous type? 非非托管类型和托管类型之间有什么区别? - What's the difference between a non-unmanaged type and a managed type? 泛型类型和类型之间有什么区别(在这种情况下)? - What's the difference (in this context) between a generic type and a type? MemberwiseClone()和在C#中分配引用类型有什么区别? - What is the difference between MemberwiseClone() and Assigning a Reference type in C#? 按值传递引用类型和普通方法有什么区别 - What's the difference pass reference type by value and normal method C# 中的 Real Literal 和 Type Casting 有什么区别? - What's the difference between a Real Literal and Type Casting in C#? 'Enum:Type'与'Enum'之间的区别是什么? - What's the difference between 'Enum : Type' and simply 'Enum' TypeInfo 中的 DeclaredMembers 和 Type 中的 GetMembers 有什么区别? - What's the difference between DeclaredMembers from TypeInfo and GetMembers from Type?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM