Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between type definition and type reference?

Tags:

c#

clr

I am reading the book CLR via C# by Jeffrey Richter.

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

What do the type reference and type definition mean here?

like image 506
Claude Tan Avatar asked Nov 07 '22 18:11

Claude Tan


1 Answers

The author is contrasting System.Type with System.TypeInfo. From the documentation:

A TypeInfo object represents the type definition itself, whereas a Type object represents a reference to the type definition.

The System.TypeInfo for a class can only be instantiated if the assembly that implements the class (the type definition) is loaded or loadable. To instantiate a System.Type, the only requirement is that the current program contains a reference to the implementing assembly.

See also What's the difference between Type and TypeInfo?

like image 164
John Wu Avatar answered Nov 14 '22 23:11

John Wu