What type

Type and type classification (.NET FrameWork underlying structure)
Preface: int a=5;// a is a variable, its essence is an object instance of System.Int32 structure

What is the type: type is the lowest level thing of any programming language (so whenever XX is a type, don’t think about its inheritance relationship, because it represents the underlying data or data structure)
type is a set of keywords, it It is the same as declaring the basic data type or abstract data structure type of an identifier; the
type determines what kind of data/data block or data structure template to be described in a piece of memory;
in .NET, the type keyword and Same as other keywords, in blue font

1) Basic data type: The identifier of the basic data type's reputation is called a variable, and the variable is used directly to store the value of the
data. The declaration of the basic data type can be in the data structure type and method body, and it is not allowed to be defined in the namespace
The definition of the basic data type is a process of defining variables;
value type: the variable declared by the basic data type of the value type directly stores the value; (int, float, char, bool)
reference type: the variable declared by the basic data type of the reference type Used to store references to values ​​(objects); (string, array, object)

2) Abstract data structure type: The type of abstract data structure can be defined in the namespace and data structure type. It is not allowed to be defined in the method body. The
class is a data structure. We put class, interface, delegate, struct, enum in parallel Relational (that can be used to declare variables) type declaration keywords are collectively referred to as abstract data structure types. The
abstract data structure type declaration is again a custom data type (model, template), that is, an abstract data structure type identification After the character is defined, it is still used as a type keyword to declare the variable (this variable is the object of the custom data type (template), or called the instantiation of the template (the instantiation of the class, the instantiation of the delegate, the structure The instantiation of, the instantiation of enumeration...));
the definition of an abstract data type is a process of creating a template (or a process of creating a custom type); the
instantiation of a template is a process of printing a template; The instantiated template can be used like other variables (variable is an object);
.NET declared abstract data structure type identifier: green font (a defined interface, enumeration uses green) and light blue Color font (a well-defined class, the structure uses light blue)
Value type: an object of the type declared by the abstract data structure type of the value type, and its value will be used to directly store the value of the object instance; (Struct, Enum );
Reference type: refers to the object of the type declared by the abstract data structure type of the class, and its value is a reference to the object instance (class, Interface, delegate)

Basic data types and abstract data types are divided into value types and reference types.
Their value types are directly stored (variable values)/(instances of objects);
their reference types are stored (references to values)/(instances of objects) Reference);

Normalized language (more conducive to my logical and clear understanding of knowledge)
1. When we use type keywords to declare a template or a variable, we call this template/variable the type keyword, for example:
class A{}, call A is a Class/A is a class type;
delegate void B(), B is a delegate/B is a
GameObject Go of delegate type ; Go is a GameObject/ Go is a
string s of GameObject type ; s is a string/s is a string Type of

The implicit inheritance of types in .NET: (everything is an object)

Implicit inheritance is automatically completed after
declaring a variable of a basic data type or a template of an abstract data type; when a variable is declared with a basic data type keyword, the value of the variable is a encapsulated class in .Net (structure ) Instance
When using the abstract data structure type keyword to declare a template, .NET will let this variable template automatically follow the path behind implicitly inherit the class/interface that has been encapsulated in .NET
Tips: some types of hidden Type inheritance relationship is invisible by pressing F12, it must be viewed in the .NET document

1) The implicit inheritance relationship of value types: (inherited by ValueType->Object)
The keyword declared using the value type is a variable/object, and the variable is used to store the value directly; in c#, all value types are implicitly inherited From ValueType)
The following describes the inheritance hierarchy of value types

Basic data types:
int keyword->Int16(struct)/Int32(Struct)/Int64(Struct)->System.Valuetype->System.Object The
above meaning refers to: when using the int keyword to declare an integer variable, This variable itself is an object of the Int32 structure encapsulated in .NET;
char keyword->System.Char->System.ValueType->System.Object //That is, a char type variable is actually a System.Char The object of the structure
bool keyword->System.Boolean(Struct)->System.ValueType->System.Objecct
float keyword->System.Single(Struct)->System.ValueType->System.Objecct
… In
summary: The variable declared by the basic data type of the value type is essentially an object of a .NET predefined structure, and this structure directly or indirectly inherits from System.ValueType

Abstract data structure type
enum keyword->System.Enum(abstrct class)->System.ValueType->System.Object(Class) The
above meaning means that when an enumeration is declared using the Enum keyword, .NET will let this Enumeration will automatically inherit the classes/interfaces that have been encapsulated in .NET automatically according to the following path. The following is the same as the
Struct keyword->System.ValueType->System.Object. In
summary: the data structure type of the value type is declared the template directly or c # tutorials are indirectly inherited from System.ValueType

2) Reference type implicitly following the python basic tutorial inheritance relationship:
basic data type:
string keyword->System.String(class)->System.Object
[]array->System.Array(class)->System.Object

Abstract data structure type:
class keyword (when the declaration inheritance relationship is not shown) -> System.Object The
above meaning means: when a class is declared with the class keyword, the class will automatically inherit from the encapsulated base in .NET Class Object
delegate keyword -> System.Delegate(class) -> System.Object
Interface keyword (when the inheritance relationship is not shown) -> is not an extension type of System.Object, and the interface declared using it does not inherit any encapsulated Good class (special)

Understanding: Using object-oriented languages ​​such as c#, everything is an object is not only a slogan, but also embodied in the underlying class hierarchy of .NET FrameWork;
1. The essence of all variables declared with basic data types: the corresponding ones have been encapsulated Good class/structure object;
for example: the string variable declared by string is essentially an object of the System.String class;
operation: string s="";//Use F12 to search for the System.String class, indicating that s is System Objects of the .String class
2. All templates declared by abstract data structure types essentially inherit the encapsulated class (except interface, which does not inherit from any encapsulated class/structure);
for example: delegate The declared delegate is essentially inherited from the System.Delegate class

When we use abstract data type declarations, we are actually creating templates;
when we use basic data types or template name declarations vb.net tutorial

When we are actually creating an instance of the template;

Therefore, whether it is a variable declared by a basic data type or an instance of a template, it is essentially
an object instance of a class/structure/interface, that is, everything is an object

Guess you like

Origin blog.csdn.net/chinaherolts2008/article/details/112853934