VB.NET study notes (data type foundation)

zhaozj2021-02-16  55

Discuss data type

The data type in .NET is the basics that the programmer needs to be carefully mastered. Two basic categories of the .NET type are "Value Type" and "Reference Type". The primitive type, enumeration and structure are value type. Class, string, standard module, interface, array, and delegate are reference types.

All types are either a value type or a reference type, but there is a case exception. Root type System.Object, it is very special because it is neither a reference type nor a value type, and cannot be instantiated. Therefore, the variable of type Object can contain value types or reference types.

However, whether the value type is still the same, their declaration is the same, of course their semantics are different.

Value type

The value type is stored directly on the stack, either in an array or in another type. The value type is always directly accessible; it is impossible to create references to value types. The value of the value type cannot be empty, and the value type variable assignment creates a copy of the assigned value.

Value Copy Creation Significance Example

DIM I as INT32 = 10

DIM J AS INT32 = i

J = 20 'i = 10

Basic type

What is the basic type? Simple talk is that if a type of value is to be described using constants, this type is the basic type. When the operands of the expression are the primitive type constant, the compiler is possible to calculate the expression at compile time. This expression is referred to as a constant expression. The basic type always has an initial value.

VB.NET defined basic types: integer (including bytes), floating point, Boolean, date, characters, and strings.

classification

Types of

Storage assignment

Integer type BYTE 1 Short 2 Integer 4 long 8 floating point value type SINGLE 4 DOUBLE 8 DECIMAL 16 Boolean 2 Date 8 Character Char 2 String String Depending on the implementation platform

If you have a heart, you can see the allocation space of Boolean and Char: .NET is Unicode to represent data, so the space occupied by English characters and Chinese characters in .NET is consistent.

转载请注明原文地址:https://www.9cbs.com/read-27042.html

New Post(0)