Visual Basic 9.0 cutting-edge broadcast-static Article (6) Relaxation of delegation and enhancement of the null type syntax

Source: Internet
Author: User

This section introduces two new features of VB9 as an auxiliary feature for data development. CLR adds many new features about delegation in. NET 2.0 (but most of them are not supported by any language ).CovariantThis feature allows you to relax the signature check when the delegate is bound to the function (supported by C #2.0 ). In order to pursue higher flexibility, VB9 decided to introduceLoose Delegation. Specify a function for the delegated instance according to the following rules:

1. The number of parameters and return value types of the function are the same as those of the delegate signature.
2. The parameter types of the function and the parameter types at the corresponding position of the delegate signature have parent-child or interface-implementation relationships, or implicit conversion rules defined by Visual Basic.

That is to say, if we have a delegate whose signature is F (Integer), we can not only specify the g (Integer) signature function for his instance, but also specify g (Double) or g (Object) signature function, because Int32 has an implicit conversion to Double and is a subclass of the Object. For example:

 Public Delegate Sub Test () Sub Test (arg As Integer) 'in the code Sub Func () Sub Func (arg As Object) Console. writeLine (arg. toString () End SubDim d As Test = AddressOf Funcd (13)

Can be empty type is supported in VB2005, and the same as C # can be converted with the Object type without semantic differences. However, VB2005 does not add C # syntax sugar, such as simplified definition syntax, lifted operator, and null value judgment operator. Although I think these syntactic sugar may not be delicious, VB9 eventually adds some. The first is the syntax defined by the question mark.

 Dim var1 As T?Dim var2? As T

The above two definitions are equivalent, meaning: when T is the reference type, the variable type is T; when T is the value type, the variable type is System. nullable (Of T ). In this way, all the definition syntaxes that can be empty can be unified, and then null values can be determined in a unified way. The second referenced syntax is the lifted operator. When the operator defined by the T type is used by the T? If the original computation result type is U, the result of the computation that can be null is U ?; Any side of the number involved in the calculation is Nothing, and the result is Nothing. In this way, the Null propagation of Visual Basic has been back for many years. Note that T? The reference type defined in the format. Although it can be a Null reference, it is not transmitted by Null and only throws an exception.

This is the end of the static Article broadcasted at the forefront of VB9. From the next article, we will enter the dynamic article on Visual Basic syntax improvement.

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.