New language changes in Visual Basic.net

zhaozj2021-02-11  212

Introduction

To quickly create an enterprise-level web application, developers must rely on commercial logic such as scalability, strongness, and reusability. In the past few years, object-oriented program is designed to be a primary approach to these requirements. Using object-oriented programming languages ​​help make large-scale systems easier to understand, easier to debug, and more rapid upgrade.

In order to enable Visual Basic developers to benefit from object-oriented, the next version of Visual Basic's next version of Visual Basic, the next version of Visual Basic will support all object-oriented language features that implement inheritance. With these language features, Visual Basic.NET will have all the capabilities needed to quickly develop enterprise-level critical applications while maintaining direct access to the world's most popular development tool.

Visual Basic.net provides a first-class object-oriented programming language characteristic, such as implementing inheritance, overloading, and parameterized constructors. In addition, developers can write code with high scalability through explicit free threads, and write code with higher maintainability through other modern language concepts such as structured abnormal processing. Visual Basic.NET will provide developers to create all the language features they need to create strong, scalable distributed web applications:

Added object-oriented programming feature

l inheritance

l

l Parameterized constructor

Other modern language features

L free thread

l Structured abnormal treatment

l Strict type check

l sharing member

l Initialization settings

Language update history

Visual Basic language has a long update history, which is related to the basic changes of the Windows platform. For example: a significant change in QuickBasic is a GUI development that supports Windows3.0 and produces the first version of Visual Basic. Creating a DLL language concept in Visual Basic 4.0 is generated to COM-programming. In Visual Basic 5.0, its language has developed to support COM controls.

With each continuous modification, Visual Basic's popularity is getting higher and higher. The new Visual Basic-oriented language features provide developers with the ability to create an enterprise-level web application, which will continue to continue this trend.

Object-oriented programming

Data storage separation and program code in traditional structured programming, there is some drawbacks. All code is written in structured instead of module. Because data elements can be accessed from any code, it may be modified without knowing the developer. This may result in very difficult runtime errors that are difficult to debug. In addition, program maintenance may become an important task. It is very difficult to understand the global impact caused by modifying a line of code in structured programming. Finally, dependent on developer control code and data results can result in lower reusability.

Object-oriented programming (OOP) solves these problems, which package data and the method implemented in it into a separate unit called objects. The data of an object can be hidden to prevent unauthorized modifications. In addition, the object discloses a set of public methods that can operate on the data. This concept is called package. Since the details and interface separation are achieved, the programming logic of the underlying can be changed in later periods without having to worry about the code of the destruction of the object.

OOP also allows developers to reuse code and data through inheritance. By inheriting from previously determined objects, developers can construct complex applications more quickly. Since writing new code always has potential possibilities with incorrectly, reusing the test-tested code can minimize the possibility of generating additional errors.

In order to adapt to these needs, Visual Basic.NET will provide some new language features that can have the benefits of the various benefits described above, making it a first-class object-oriented programming language.

inherit

The highest voice in the requirements of Visual Basic features is the support of inheritance. The development requirements of the Internet era are quickly assembled and a large number of reuse. Visual Basic is now fully implemented, including inheritance of visual formation. Developers can use new keyword inherits from a existing class.

Class1

Function getcustomer ()

...

END FUNCTION

Class2

Inherits Class1

Function GetRDERS ()

...

END FUNCTION

Inherited statements support all properties related to inheritance. The instance of the derived class supports the methods and interfaces supported by all base classes. Of course, derived classes can extend the collection of methods and interfaces supported by the base class. Detective classes can use Overrides keywords to replace the methods defined in the base class. To reduce programming errors, Visual Basic prevents accidental replacement a function. Only functions that are declared "alternative" are allowed to be replaced in the derived class.

Overload

Visual Basic is now allowed to be overloaded, which enables the developer to create a process or function of the same name, but the parameter type is different.

The inheritance is especially useful when the object model is similar to the process to be similar but operated on different types of data. For example: a class that may be characterized as several different data types can have such a Display process:

Overloads Sub Display (THECHAR AS CHAR)

...

Overloads Sub Display (THEINTEGER AS INTEGER)

...

Overloads Sub Display (THEDOUBLE AS DOUBLE)

If you don't inherit, you need to use a different name for each process or use the Variant parameter. Overload provides a more clear and more effective way to handle multiple data types.

Parameterized constructor

Parameterized constructor (or referred to as "constructor") allows you to deliver parameters to this instance when you create a new instance of a class. The constructor is required for object-oriented programming. Because it allows the user-defined constructor to pass parameters through the creator of the instance. They create and initialize the code of the client program by allowing a new object instance to simplify the code of the client program in a separate expression.

Other modern language features

Visual Basic.net adds some new concepts with strong and scalability applications. These features include free thread, structured exception handling, strict type security, etc., and new features that can improve productivity, such as initialization settings and shared members.

Free thread

The code they have written is synchronized when developers create an application in Visual Basic. This means that each line code is to be executed before the next line of code. When developing web applications, scalability is the key. Developers need to be parallel to become possible tools.

Through free threads, developers can generate a thread to complete some tasks of running time, perform a complex query or run a multi-part calculation, and other parts of the application continue to execute, provide asynchronous processing.

SUB CREATEMYTHREAD ()

DIM B AS BackgroundWork

Dim t as thread

SET B = New BackgroundWork ()

Set T = New Thread (New ThreadStart (Addressof B.DoIT)

T.Start

End Sub

Class Backgroundwork

Sub DOIT ()

...

End Sub

END CLASS

Structured abnormal treatment

Developing an enterprise-class application requires creating reusable and maintainable components. In the past Visual Basic version, a disputeatic aspect of the Basic language is its support for error handling. Developers have found consistent error handling solutions means a lot of assignment code. Error handling method using existing on Error Goto statements sometimes slows the development and maintenance of large-scale applications. It reflects such a problem: such as Goto means that when an error occurs, the control shifts to a marked location in the subroutine. Once the error code is running, it must be turned to the other clear position, while the latter has to pass a standard goto, and finally to exit the process through other goto or exit. Handling several different errors will generate difficult-to-read code and will result in frequent errors when the execution path is not fully considered. With TRY ... CATCH ... FINALLY, these problems will not be present, and developers can nest their exception handling, and this is a control structure for writing cleaning code under normal conditions and abnormal conditions.

SUB SEH ()

Try

Open "testfile" for output as # 1

Write # 1, CustomerInformation

Catch

Kill "Testfile"

Finally

Close # 1

END TRY

End Sub

Strict type check

The current Visual Basic language is very free on its possible implicit type. For parameters passwords other than reference, the Visual Basic compiler allows almost any data type to convert to other data types by force-to-process type conversion. If the value to be converted cannot be converted without data loss, the mandatory conversion of the runtime may fail. By adding a new compilation option, Visual Basic can generate compile time errors for any conversion that may occur at runtime. Options Strict is improved by modifying an error while requiring a conversion that may fail at runtime or automatic conversion outside the user expectations between the digital type and strings.

Shared member

Shared members are data and function members that are shared by all instances of classes. A single instance of a data member or function is a single instance of a data member or a function in all instances of the class is required to use inherited Visual Basic applications. A shared data member exists independently in each instance of the class. The shared method is different from a normal method, which is not an example of implicit delivery class. For this reason, unrestricted references to non-shared data members in the sharing method are not allowed. Common shared members can be accessed indirectly, and they can be bound to the instance of the class.

Initialization setting

Visual Basic.NET supports initialization in the declaration of variables. Initialization settings can be used anywhere in the control structure. The semantics containing the process grade declaration of the initialization settings are the same as a declarative statement. In other words, the statement

DIM X as integer = 1

DIM X as integer

X = 1 is the same.

Conclude

Visual Basic is now a first-class object-oriented programming language, using Visual Basic.NET, developers can create highly scalable code through explicit free threads. The code they have written has increased the use of modern language concepts such as structural abnormalities, which will have high maintenanceability. Visual Basic will provide developers to create strong, retractable distributed web applications to provide all language features they need.

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

New Post(0)