Você está na página 1de 6

International Journal of Advanced Engineering Technology

E-ISSN 0976-3945

Review Article

INTRODUCTION TO NEW FEATURES OF VISUAL


BASIC 2010
1

Mayur Patel, 2Neha Patel, 3Nirmit Shah

Address for correspondence


1

Department of Computer Engineering, 2 Department of Information Technology-Faculty of Technology


and Engineering, Charotar University of Science and Technology, Anand, Gujarat
3

General Department- Parul Polytechnic Institute

ABSTRACT
The Visual Basic language has always been an exceptional production tool for building applications. It
continues to provide easy access to the Microsoft.Net Framework, allowing developers to write
applications that extent desktop, phone, browsers and even the cloud. This paper reviews examines the
new features added to Visual Basic 2010 like Statement Lambdas, Line Continuation, Auto Implemented
Properties, Dynamic Language Runtime, Multi Targeting.

INTRODUCTION

tedious code and investigated ways to get

Visual Basic 2010 contains many time

the compiler to do the work instead.

saving features that help developers get

New Features

more done with fewer lines of code. In the

Here in this paper we will discuss feature

past, Visual Basic and C# were developed

like Statement Lambdas, Implicit Line

by separate teams, so that resulted in

Continuation, Auto Implemented Properties,

features appearing in one language before

Dynamic Language Runtime and Multi-

other.

Targeting. Now lets delve into some

For example , C# had auto

implemented

properties

and

collection

features one by one.

initializers, which werent in Visual Basic,

Statement Lambdas

and Visual Basic had features such as late

In Visual Studio 2008, VB lambdas allowed

binding and optional parameters that werent

programmers

in C#.

expressions, e.g. as an argument to a

Now to address these features Microsoft

method. In Visual Studio 2010, VB now

merged the Visual Basic and C# teams to

allows you to write lambdas as statements

make languages advance together.

(i.e. as a regular method body rather than

Visual Basic design team looked at places

just a single expression). It also allows

where developers often have to write a lot of

expression lambdas without a return type.

IJAET/Vol.I/ Issue II/July-Sept.,2010/10-15

to

write

functions

as

International Journal of Advanced Engineering Technology

Here's an example:
Module Module1
Sub Main ()
Dim q = Sub ()
Console.WriteLine ("Hello World!")
q ()
End Sub
End Module

'Sub'/'Function'

(and

E-ISSN 0976-3945

'End

Sub'/'End

Function') can be used in an expression


context, so you can use them as arguments
(just like Function() expression lambdas in
Visual Studio 2008):
Here's an example:
Module Module1
Delegate Function SomeDelegate
(ByVal x As Integer) As Integer
Sub Main()
Dim q = New SomeDelegate
(Function(x As Integer) As Integer
Return x + 2
End Function)
End Sub
End Module

The expression is evaluated when the


lambda is executed, but nothing is returned.
The real work in Visual Basic lambdas has
been around 'statement lambdas'. This
allows you to write full-fledged statements
in lambdas:
Here's an example:
Module Module1
Sub Main ()
Dim q = Sub(x As String)
Console.WriteLine ("Hello")
Console.WriteLine ("World!")
Console.WriteLine(x)
End Sub
q("Hello World!")
End Sub
End Module

You can define variables inside lambdas,


and even nest lambdas:

This will make it easier to write small pieces


of code for APIs that require procedures as
arguments. Creating a regular method,
which often appears out-of-place, will no
longer be required for such API calls.
Implicit Line Continuation
Traditionally, when a statement in VB has
been split up across multiple lines, you had
to

Here's an example:
Module Module1
Sub Main ()
Dim t As Integer = 22
Dim q = Sub ()
Dim s = Function (str As String)
Console.WriteLine (str)
Return 0
End Function
s ("Hello World!")
End Sub
q ()
End Sub
End Module

In this case, lambda q () is invoked, which


then invokes lambda s () with the argument
"Hello World! Note that the keywords
IJAET/Vol.I/ Issue II/July-Sept.,2010/10-15

use

line-continuation

underscore

character (_) to indicate that the statement


wasnt complete. For example, with VB
2008 the below LINQ query needs to
append a _ at the end of each line to
indicate that the query is not complete yet:
Here's an example:
Sub Page_Load (ByVal sender As Object, ByVal
e As System.EventArgs) Handles Me.Load
Dim Northwind As New NorthWindEntities
Dim products=From p In Northwind.Products _
Where p.UnitInStock > 0 _
Select p
GridView1.Datasource = products
GridView1.DataBind()
End Sub

International Journal of Advanced Engineering Technology

E-ISSN 0976-3945

The VB 2010 compiler and code editor now

For example, the code below demonstrates

adds support for what is called implicit line

how to implement a Person class using

continuation support which means that it

VB 2008 that exposes two public properties

is

- Name and Age:

smarter

about

auto-detecting

line

continuation scenarios, and as a result no

While explicitly declaring properties like

longer needs you to explicitly indicate that

above provides maximum flexibility, Ive

the statement continues in many, many

always found writing this type of boiler-

scenarios. This means that with VB 2010

plate get/set code tedious when you are

we can now write the above code with no

simply storing/retrieving the value from a

_ at all:

field. You can use VS code snippets to help

Here's an example:

automate the generation of it but it still

Sub Page_Load (ByVal sender As Object, ByVal


e As System.EventArgs) Handles Me.Load

generates a lot of code that feels redundant.

Dim Northwind As New NorthWindEntities


Dim products=From p In Northwind.Products
Where p.UnitInStock > 0
Select p
GridView1.Datasource = products
GridView1.DataBind()
End Sub

C# 2008 introduced a cool new feature


called automatic properties that helps cut
down the code quite a bit for the common
case where properties are simply backed by

Auto Implemented Properties

a field. VB 2010 also now supports this

Prior to VB 2010, implementing properties

same feature.

within a class using VB required you to

Using

explicitly declare the property as well as

feature of VB 2010 we can now implement

implement a backing field variable to store

our Person class using just the code below:

its value.

the

auto-implemented

properties

Here's an example:
Public Class Person

Here's an example:
Public Class Person
Private _name As String
Private _age As Integer
Public Property Name() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name=value
End Set
End Property
Public Property Age() As Integer
Get
Return _age
End Get
Set(ByVal value As String)
_age=value
End Set
End Property
End Class

IJAET/Vol.I/ Issue II/July-Sept.,2010/10-15

Property Name As String


Property Age As Integer
End Class

When you declare an auto-implemented


property, the VB compiler automatically
creates a private field to store the property
value as well as generates the associated
Get/Set methods for you. As you can see

International Journal of Advanced Engineering Technology

E-ISSN 0976-3945

above the code is much more concise and

the IDynamicMetaObjectProvider interface.

easier to read.

The DLR

The syntax supports optionally initializing

automate a lot of code analysis and code

the properties with default values as well if

generation tasks. This enables language

you want to:

implementers to concentrate on unique

and the

.NET

Framework

language features.

Here's an example:

Enables Dynamic Features in Statically

Public Class Person

Typed Languages

Property Name As String=Mayur Patel


Property Age As Integer=25

Existing .NET Framework languages such

End Class

as C# and Visual Basic can create dynamic


Dynamic Language Runtime

objects and use them together with statically

The Dynamic Language Runtime (DLR)

typed objects. For example, C# and Visual

from Microsoft is an effort to bring a set of

Basic can use dynamic objects for HTML,

services that run on top of the Common

Document Object Model (DOM), and .NET

Language Runtime (CLR), in upcoming

reflection.

.NET Framework 4.0 has this built within in

Provides Future Benefits of the DLR and

it and provides language services for several

.NET Framework

different dynamic languages.

Languages implemented by using the DLR

The

DLR

provides

the

following

can benefit from future DLR and .NET

advantages.

Framework improvements. For example, if

Simplifies Porting Dynamic Languages to

the .NET Framework releases a new version

the .NET Framework

that has an improved garbage collector or

The DLR allows language implementers to

faster assembly loading time, languages

avoid creating lexical analyzers, parsers,

implemented by using the DLR immediately

semantic analyzers, code generators, and

get the same benefit. If the DLR adds

other tools that they traditionally had to

optimizations such as better compilation, the

create themselves. To use the DLR, a

performance also improves for all languages

language needs to produce expression trees,

implemented by using the DLR.

which represent language-level code in a

Enables Sharing of Libraries and Objects

tree-shaped

helper

The objects and libraries implemented in

routines, and optional dynamic objects that

one language can be used by other

implement

languages.

structure,

runtime

IJAET/Vol.I/ Issue II/July-Sept.,2010/10-15

The

DLR

also

enables

International Journal of Advanced Engineering Technology

E-ISSN 0976-3945

interoperation between statically typed and

and services, including Silverlight and

dynamic languages. For example, C# can

COM. Binders encapsulate a language's

declare a dynamic object that uses a library

semantics and specify how to perform

that is written in a dynamic language. At the

operations in a call site by using expression

same time, dynamic languages can use

trees. This enables dynamic and statically

libraries from the .NET Framework.

typed languages that use the DLR to share

Provides Fast Dynamic Dispatch and

libraries and

Invocation

technologies that the DLR supports.

The DLR provides fast execution of

Multi Targeting

dynamic operations by supporting advanced

The coolest thing about all the features in

polymorphic caching. The DLR creates rules

Visual Basic 2010 is that you can even use

for binding operations that use objects to the

them in projects that target the .NET

necessary runtime implementations and then

Framework

caches these rules to avoid resource-

Framework 3.5. This means that statement

exhausting binding computations during

lambdas, implicit line continuation, auto

successive executions of the same code on

implemented properties all will work in

the same types of objects.

existing projects without having to retarget

gain

2.0

access to all

through

the

the

.NET

to the .NET Framework 4.0.


The one exception is Embed Interop Types,
which has a dependency on types that are
only in .NET Framework 4; as a result you
cant use it when targeting .NET Framework
version 2.0 through 3.5.
CONCLUSION
Since its inception in 1991, Microsoft Visual
Basic has revolutionized the way developers
create applications for Microsoft Windows.
Through

features

such

as

Statement

DLR Architecture

Compliance, Database Access, Native code

The DLR uses binders in call sites to

compiler, Microsoft has worked hard to

communicate not only with the .NET

keep developers well equipped with latest

Framework, but with other infrastructures

innovations

IJAET/Vol.I/ Issue II/July-Sept.,2010/10-15

in

rapid

application

International Journal of Advanced Engineering Technology

development. In Visual Basic 2010, Visual


Basic

has

been

expanded

to

make

developers even more productive with cross


platform application environment. These
features provide the power and performance
needed to create applications that run in
mission critical scenarios.
ACKNOWLEDGEMENT
The authors wish to thank Research paper
review committee, Faculty of Technology
and Engineering, CHARUSAT and Dr. Y. P.
Kosta, Dean-Faculty of Technology and
Engineering, Charotar University of Science
and

Technology,

Changa

for

their

suggestions, encouragement and support in


undertaking the present work. Special thanks
to the Management for their moral support
and continuous encouragement.
REFERENCES
1. Sean Alexanders Advanced Microsoft
Visual Basic 6.0, Second Edition, WP
Publications and distributors Pvt ltd 2001.
2. Bill Sheldon, Billy Hollis, Kent
Sharkey, Gaston Hillar, Rob Windsor,
Jonathan Marbutts Professional Visual
Basic 2010 and .NET 4, Wrox Guide 2010.
3. http://msdn.microsoft.com
4. http://blogs.msdn.com
5. http://webcache.googleusercontent.com
6. http://weblogs.asp.net

IJAET/Vol.I/ Issue II/July-Sept.,2010/10-15

E-ISSN 0976-3945

Você também pode gostar