Basic concepts and syntax of Visual Basic. Net

Source: Internet
Author: User

Starting from the basic concepts and syntax, learning a language, especially now is a visual development, but I suggest not to drag several widgets first, instead, you must first understand the concepts, syntaxes, and specifications of the language. Although VB. Net is very similar to the previous VB6 syntax, the current VB. Net is a brand new object-oriented language, so there are some differences between the two.

As we all know, now VB. net has fully supported various object-oriented features, and there are some other.. Net environment: inherit, overload, override attributes and methods, implement constructor and destructor, interface, Delegate, exception, namespace, assembly, feature programming, multithreading, sharing members.

First, briefly describe the VB. Net syntax, although it is so similar to VB6. Therefore, VB. Net statements are a review of VB6 statements, but some statements are not found in VB6.

VB. Net statements include declaration statements, value assignment statements, condition statements, loop statements, array processing statements, exception statements, control flow statements, call statements, and lock statements.

  Statement

Declaration in VB. Net and medium usually refers to the declaration of variables.

We use the Dim modifier to declare local variables. You can still use Const to modify the variable as a constant. Static is still valid as a description of Static variables.

Declaration example (We will describe classes and arrays later)

Const s As String = "Hello" constant local variable
Dim B As Boolean rule local variable
Static I As Int32 Static local variable

  Variable accessibility

The above three variables are all local variables. We know that local variables are visible only in the declared regions and cannot be accessed outside the scope, for those that require more access control, VB. net provides richer modifier keywords.

Accessibility Modification

Description

Public

If the declared element is public, there is no restriction on the accessibility of the public element.

Private

Declared elements can only be accessed from the same module, class, or structure.

Protected

The declared element can only be accessed from the same class or the derived class of the class.

Friend

Declarative elements can be accessed from the same project, but cannot be accessed from outside the project.

Protected Friend

The declared element can be accessed from a derived class, within the same project, or both.

Examples of accessibility (note the relationship between TestB, TestC and TestA)

Public Class TestA
Public I As Int32 = 100 unlimited access
Private s As String = "Hello" only TestA can access
Protected B As Boolean = True only TestA and Its Derived classes can access
Friend d As Double = 3.1415926 only accessible to the same project class
Protected Friend l As Long = 100000
End Class
Public Class TestB
Inherits TestA
Public Sub New ()
MyBase. B = False
MyBase. d = 3.14
MyBase. I = 10
MyBase. l = 10000
End Sub
End Class
Public Class TestC
Public Sub New ()
Dim a As New TestA
A. d = 3.14
A. I = 10
A. l = 1000
End Sub
End Class

If you have the foundation of VB6, I believe it will soon be possible to transition to VB.net.

Related Article

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.