New features in visual basic 10

Solo disponible en BuenasTareas
  • Páginas : 12 (2927 palabras )
  • Descarga(s) : 0
  • Publicado : 3 de junio de 2011
Leer documento completo
Vista previa del texto
New features in Visual Basic 10

Jonathan Aneja, Program Manager

Lucian Wischik, Specification Lead

Paul Vick, Principal Architect

April 9, 2010

Introduction 1
New Language Features 2
Multiline Lambdas 2
Sub Lambdas 3
Single-line Sub Lambdas 3
Implicit Line Continuation 3
Auto-implemented Properties 6
Collection Initializers 7
Array Literals 7Nullable Optional Parameters 8
Generic Variance 8
Covariance 8
Contravariance 9
Limitations 9
Interop with Dynamic Languages 10
Compiling without PIAs 10
Relationship with C# 11
Resources 12


We are proud to release Visual Basic 10, the latest version of the Visual Basic language. This is the version of the language that ships with Visual Studio 2010 and .NET4.

Microsoft has committed to a policy of “co-evolution” between Visual Basic and C#, where major new features will appear in both languages at the same time, and important new features that appear in both languages in this release include interop with the Dynamic Language Runtime, and the ability to build solutions that no longer require Primary Interop Assemblies to be deployed on end-usermachines.

Some new features in this version of the language, such as implicit line continuations, provide a cleaner or simpler syntax that will be used in almost every function you write. Other new features, such as statement lambdas, enable powerful idioms in new Microsoft frameworks such as Silverlight 4 and the Task Parallel Library.

Visual Basic 10 also marks the first release in whichthe language specification is deployed with the product. It can be found in C:\Program Files (x86)\Microsoft Visual Studio 10.0\VB\Specifications.

Visual Basic has always strived to be the most productive tool for building line-of-business, data-centric applications. Version 9.0 of the language delivered Language Integrated Query (LINQ), first-class XML support, as well as other core featuressuch as nullable types. We are proud to release Visual Basic 10, which makes the language cleaner and simpler and more powerful.

New Language Features

Multi-Line Statement Lambdas

A statement lambda is a lambda expression that represents a function containing one or more statements.

Dim nums() As Integer = {1, 2, 3, 4, 5}

nums = Array.FindAll(nums, Function(n)Console.WriteLine("testing " & n)
Return n > 2

End Function)

Just like regular lambdas, the compiler will infer the type of each parameter where possible (in this case inferring n as Integer). The compiler will also infer the lambda’s return type by using the dominant type algorithm (see section 8.13 ofthe Language Specification, usually at “C:\Program Files (x86)\Microsoft Visual Studio 10.0\VB\Specifications”) to choose between the types of each expression in a Return statement. For example:

'numDelegate is an anonymous delegate compatible with Func(Of Integer,
Dim numDelegate = Function(n As Integer)

If n Mod 2 = 0 ThenReturn 3
Return 3.14
End If

End Function

In this case, the compiler sees that the return type could be Integer or Double, and so it picks Double as it is a wider type that can encompass any Integer.

Alternatively, you can explicitly specify the return type youwant by using an As clause. In this case, the compiler will just use “Single” and will not attempt to infer a return type:

Dim lambda = Function(n As Integer) As Single
If n Mod 2 = 0 Then
Return 3
Return 3.14
End If
End Function

Sub Lambdas

tracking img