Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Type in VB.NET

Shulou Source: shulou.com Published: 2022-06-02 08:52:00 09月20日 Update

This article mainly introduces how to use Type in VB.NET, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

We must all know about the data type of VB.NET, but it is still a difficulty for beginners. In fact, in the simplest program, the data type can not be specified, that is, variables can use various types, but in a complex program, it is very dangerous to do so, because it is likely to give the same variable a different type, which leads to program error.

Therefore, for the sake of program rigor and ease of viewing, it is necessary to define data types correctly. Another reason for defining data is that different data takes up different amounts of memory. For example, Interger data takes 2 bytes, while long integer data takes 4 bytes. Define the appropriate data type, whether you believe it or not, it can save memory! The VB.NET record definition is a method of handing control to the user. It allows the user to define their own data type. The VB.NET record definition uses the keyword "Type" by:

Type [data Type Identifier] As End Type

For example, a VB.NET record defines an address data:

Type Address Street As String ZipCode As String Phone As String End Type

This address data includes three attributes, block, zip code, and phone number, which can be defined as this type of data:

Dim MyHome As Address

When you want to call or change the value of "MyHome", it is similar to the operation on the properties of the object:

Variable name. Domain name = "."

To simplify the repetition of writing, you can use the keyword "With":

With MyHome. Street = "Fucheng Road" .ZipCode = "100037" .Phone = "12345678" End With Thank you for reading this article carefully. I hope the article "how to use Type in VB.NET" shared by the editor will be helpful to you. At the same time, I hope you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Data type program article different variable key keyword memory address byte property method user rigorous appropriate complex dangerous necessary three Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Docker MySQL vpn Xiaomi