Friday, October 8, 2010

VB.Net language improvements


We have a lot of programming forum or news group can see the C + +, VB supporters will be called a toy language (Toy Language). Where VB is the most criticized it does not really support the object-oriented programming (oop).

In the new Visual Basic, these will be the last. Visual Basic.NET will truly support the oop. Succession (inheritance), polymorphism (polymorphism) and heavy (overloading). Of course, more. Including some new data structures, structural error control (Error Handing) and thread. These will be supported by the new VB.

Inherit

Suppose you write a function that contains only the name of a basic class BaseClass:

Function GetCustomerName ()''Do some stuffEnd Function

If you want to create a new class, and use the BaseClass in GetCustomerName function. But do not want to rewrite the code for a code. Then by inheritance, you can write a new class:

Inherits BaseClassFunction GetCustomerID ()''Do some stuffEnd Function

Overload

Overload is to build you two have the same name but different attributes of the function parameters of the process. Suppose GetCustomID function input and output according to the user's ID number. Then the function may have the following two types:

Function GetCustomerID (custname as string) As Integer''by users through the user name IDEnd FunctionFunction GetCustomerID (purch as long) As Integer''single number access to users according to shopping IDEnd Function

By overloading, you can call for different types of input with a function.

In fact to some extent now provided in the VB function overloading, consider the following functions:

Function GetCustomID (vIN As Variant) As LongGetCustomID = vINEnd Function

You can call the following two ways:

ID = GetCustomID ("123")

Or

ID = GetCustomID (123)

So why the introduction of the new overloaded version of it? This is because the new Visual Basic introduced new features: type-safe (default type safety). In Visual Basic.NET in, Variant type will no longer exist, a detailed description see the following upgrade parts on the content.

Polymorphism

Polymorphism is in a class in the process of re-definition of a function. For example, you need to create a subclass of BaseClass based, but they need to re-write GetCustomerName function, in the new version of VB, you can write:

Inherits BaseClassFunction GetOrders () Overrides Function GetOrders ()... End Function

Thread

The new structure of part of the Visual Basic language will contain a multi-thread, a thread to establish the following example:
set t = New Thread (New Threadstart (AddressOf (BaseClass.Function1))
From the example above you can see, Visual Basic.NET AddressOf function in the real return function pointer. This course of API calls, for example, aspects of the callback function will be helpful.

Error handling (Error Handling)

Visual Basic.NET Another big improvement is the error handling. Visual Basic will provide the try ... catch ... finally structure, like Delphi, as in (Microsoft's original text is: just like those "respectable" languages :-))銆?For example:

Sub SafeWrite () TryOpen "Testfile" ... Write # 1CatchKill "Testfile" FinallyClose # 1End TryEnd Sub

Upgrade

When the code is upgraded, Visual Basic.NET upgrade will create a new project. Here a few examples to illustrate through your code to do those upgrades

Variant type to the Object type

Previous versions of Visual Basic support the Variant data type, the type can be set to a fixed level in addition to any raw data outside the string type and Empty, Error, Nothing, and Null. In Visual Basic.NET in, Object data type can be set to any raw data type and Empty, Error, Nothing, Null, and object pointer. When you upgrade to Visual asic.NET project, any definition will change Variant Object. Similarly, when you insert the code editor, Variant keyword will be replaced by Object.

Short Integer data types to data types

In Visual Basic 6.0 in, 16bit number is now known as Short. 32bit number is called Integer (64bit number called Long). When the project is upgraded, the data definition will make the following changes:

Dim x As Integerdim y as Long

Changed to:

Dim x As Shortdim y as Integer

Attribute grammar

Visual Basic.NET syntax for custom attributes merry more intuitive to change the Get and Set into one. For example, the original property as follows:

Property Get MyProperty () As Integerm_MyProperty = MyPropertyEnd PropertyProperty Let MyProperty (NewValue As Integer) m_MyProperty = NewValueEnd Property

Change after the upgrade:

Property MyProperty () As ShortGetm_MyProperty = MyPropertyEnd GetSetm_MyProperty = ValueEnd Set End Property

VB Forms to Windows Forms

Visual Basic.NET include the new forms package, Windows Forms, Windows Forms contains embedded menu editor. Your VB form will be upgraded to Windows Forms.

Interface

In previous versions, the public class interface for the user is always hidden. In Visual Basic.NET, the public class in the code window, browse and edit.

Upgrade report and comments

When the project is upgraded, the upgrade report will add to your project, detailing all of the upgraded code you need to make changes. At the same time the code will prompt you to pay attention to adding comments to any potential problems. These notes automatically appear in the task list in Visual Basic.NET.






相关链接:



How to short-term consultants into your team



RFID into the competition for the critical period



SWF TO MOV



FLV To IPhone



QT to WMV



mencoder exe has stopped working ELIMINATE



U.S. export control policy toward China brewing adjustment



Fireworks produced lovely "onion" Little P child



Best Install And Setup



Simple E-Mail Tools



Cleverly hide an important part of the worksheet so that no leakage



REVIEW: Liu's "marathon" Life



Farewell babyface, iSee 1 minute to create face-lift effect



HEALTH And Nutrition for you



No comments:

Post a Comment