VB.net learning notes (4) Data Type-Value Type

Source: Internet
Author: User

1. system. Object
System. object is the parent class (base class) of all VB.net classes ).
To convert an object to its parent class, you can only use the methods provided by the parent class.
The tostring method can be used to obtain the string representation of any object. This method is implemented by default by returning the type of the object.

2. VB.net type: Value Type and reference type
VB.net mainly has two variable types: Value Type and reference type.
Value Type: the basic data type (except string) is located on the stack. The storage memory size is known, so the speed is fast.
Reference Type: object, String, etc., in the managed heap, the size is allocated by the dynamic memory. Its first address is placed on the stack for reference.

All value types can be referred to as structure types in VB.net.

3. Basic Types
Byte system. byte
Short system. int16
Integer system. int32
Long system. int64
Single System. Single
Double system. Double
Decimal System. Decimal
Date system. datetime
Boolean system. Boolean
Char system. Char
String System. String
String is the only reference type in the basic type.

4. condition if... then...
Can be used with else or elseif
Because the program is executed sequentially, in order to achieve the best performance, you can place the most common conditions at the very beginning of the condition. If this is true, the following will not be tested.

5. comparison operator: = <= >=>
And or are used for logical superposition.
To achieve the best performance, VB.net provides andalso and orelse, which adopt the Shortest Path Optimization comparison. When comparing the preceding conditions to obtain the logical value, you do not need to compare them later.
Eg: If a> 0 andalso B> 0 then' if the first part is false, no tests are required later.
If C> 0 orelse D> 0 then'

In addition, the object comparison method is: Is isnot
Eg: If mystring. GetType is GetType (integer) then', check whether it is int32.

The above two ends. When performing operations on an object, two conditions are often written separately. First, the condition is determined not to be null, and then a value is obtained.
With the above, you can write in a sentence:
Eg: If mystring isnot nothing andalso mystring. length> 5 then' is not null, then take the length.

6. Select case
Tip: Like other statements, the SELECT statement can be automatically tracked by tab. Different Input positions can be switched by tab.
The last condition is available in case else.

7. Boolean
The values include true and false. In order to adapt to the previous VB6, it can also be converted to integer, true to-1, false to 0.

In order to adapt to different systems, press ENTER line breaks. Vbcrlf is still available in VB.net
Standard Syntax: environment. newline

8. Integer

Note:

Int16, short, uint16, ushort

Int32, integer, uinteger, uint32

Int64, uint64, long, ulong, uint64

Before the net standard is used, it is because when it is migrated to different platforms, such as 64-bit systems, some of the following statements are written to be compatible with the previous version. In the future, integer may not be 32-bit, it may be 64-bit on a 64-bit machine.

(1) Short int16

It occupies two bytes, but sometimes the machine may occupy four bytes to optimize the speed, but its value will not change.

The corresponding SQL type is smallint.

(2) integer int32

4 bytes. Int32 can be used to solve the migration system problem. Integer is available if it is not related to the underlying implementation mode.

The corresponding SQL is of the integer type.

(3) Long int64

8 bytes. The corresponding SQL type is biginteger.

(4) For the unsigned type, you can add u to the front. The value is non-negative and the range is doubled.

Extended Range is not the main reason for unsigned numbers, but only to characterize some features, such as uint32 and 32-bit machine pointer addresses have the same features.

8. decimal point (floating point)

It must be noted that currency has been disabled.

(1) single double

The single-precision ending number is 6 bits, and the double-precision ending number is 14. The precision and range of each expression are different.

Dim A as long = long. maxvalue

Assign values can be directly written after definition. Maxvalue and minvalue can be used after each type.

(2) decimal

Although the expression range of single and double is large, they are not accurate enough. Increasing decimal can reach 28 valid values.

A total of 16 bytes of 128 bits, of which 1 sign bit, 96 integer values, the remaining 31 bits are proportional factors, the default is 10, at the same time, 31 digits also include the rear 0 in the ending number.

(3) Char byte

Because VB.net is Unicode, there are 2 Characters in char, which can be expressed in both English and Chinese characters.

Char is unsigned, and negative is incorrect. Char cannot be directly converted to the numeric type. It must be specified

From character to value: ASC () ASCW ()

From numeric to character: CHR () chrw ()

In addition, you can add C after the character to indicate that it is a char type.

Dim A as char = "D" C' because sting is also a double quotation mark, adding C makes it clearer that it is a char

If the char in VB.net cannot be the same as the char in VB6 during the same com interaction, it must be replaced by byte.

(4) datetime

Stores the IEEE 64-bit (8 bytes) value, which indicates the date from January 1, 9999999, and from midnight 12:00:00 to 11:59:59 ..

Time. Each increment indicates
The first January 1 nanoseconds since January 1, 100. Maximum Value
10000 nanoseconds before January 1, 100.

We can see that it is not the double type of VB6 in the past. To be compatible with VB6, tooadate and fromoadate are supported.

Now () continue to use, add utcnow () (that is, Greenwich Mean Time)



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.