Blue Theme Orange Theme Green Theme Red Theme
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Home | Forums | Videos | Photos | Blogs | Beginners | Advertise with Us
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
6 Months Free & No Setup Fees ASP.NET Hosting!
Search :       Advanced Search »
Home » Visual Basic Language » Chapter I: VB 2008 Overview

Chapter I: VB 2008 Overview

In this overview, we will take a look at some of the major language differences between Visual Basic 2008 (VB 2008), C# 3.0, and Visual Basic 6.0 (VB6).

Technologies: Visual Basic Language
Author Name: Guy Fouche and Trey Nash
Total downloads : 0
Total page views :  18335
Rating :
 2.5/5
This article has been rated :  2 times
  Add to Technorati Add to Technorati    Digg This Digg This    Add to del.icio.us Add to del.icio.us
    Rate this article Read/Post comments Support Us   Printable Version 

Chapter Contents
1. Page I: Introduction
2. Page II: CLR Garbage Collection
3. Page III: A Simple VB 2008 Program
4. Page IV: What's New in VB 2008
5. Page V: What's New in VB 2008 (cont...)
6. Page VI: Summary

Nevron Diagram
Become a Sponsor
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 

LINQ to Objects

LINQ to Objects allows you execute SQL-like queries over your arrays and collections. Executing these queries, you are able to filter your collection for more specific processing. The following example executes a simple query against an array of integers:

Imports System
Imports
System.Linq
Public
Class EntryPoint
    Shared Sub Main()
        Dim someNumbers As Integer() = {5, 4, 3, 2, 1, 0}
        Dim query = From x In someNumbers _
        Where x >= 3 _
        Select x
        For Each item In query
            Console.WriteLine("{0} is >= 3", item)
        Next

    End Sub

This code filters someNumbers to create query, and query will contain the three integers, which are those greater than or equal to 3. The For Each . . . Next statement will loop through query and produce the following results:

5 is >= 3
4 is >= 3
3 is >= 3

Lambda Expressions (Inline Functions)

Lambda expressions provide you with a way to create inline, anonymous methods. The functions you create do not need to be typed, as they infer their types at run time. Creating a VB method to determine even numbers might look like the following:

Shared Function IsEven(ByVal x As Integer) As Boolean
    If x Mod 2 = 0 Then
        Return True
    Else
        Return False
    End If

End
Function

Using an inline function, you can reduce the amount of code needed to accomplish the same purpose, as in the following code snippet:

Function(n) n Mod 2 = 0

Extension Methods

Extension methods allow you to add methods to an existing CLR type. This enables you to expand the functionality of a type without needing to create a subclass. The following example shows the syntax for an extension method:

<Extension()> _
Public
Function IsTickerValid(ByVal aTicker As String) As Boolean
    Dim ValidTicker As Boolean = True
    If aTicker.Length > 4 Then
        ValidTicker = False
    End If
    Return ValidTicker

End
Function

Extension methods avoid the need to create a separate class, with a shared method, to validate the ticker symbol.

Anonymous Types

Using anonymous types, you are able to declare, define, and use types that the VB compiler will generate for you in the background. Anonymous types are able to infer field names and will create properties for these fields as well. This example shows an anonymous type declared in VB:

Dim anAnonymous = New With {.FirstName = "Jodi", .LastName = "Fouche"}

IntelliSense Everywhere

When using extension methods and anonymous types, you will find that the VB IDE is aware of these types and methods. As such, it includes your extension methods with the extended type's methods in all IntelliSense lists while coding. Anonymous types will show their compilergenerated properties in IntelliSense lists while coding.

Nullable Types, Enhanced in VB 2008

Nullable type syntax is enhanced in VB 2008. A new type modifier (?) allows you to define your types as nullable. The following code snippet demonstrates the current syntax and the new shortcut.

Dim x As Nullable(Of Integer)
Dim
y As Nullable(Of Integer)
Dim
x As Integer?
Dim
y As Integer?

Relaxed Delegates, Enhanced in VB 2008

Relaxed delegates extend and enhance the VB's implicit conversions to delegate types. Using relaxed delegates allows you to omit arguments from event handlers. For example, the following code statements are now valid in VB:

Sub OnClick(ByVal sender As Object, ByVal e As Object) Handles aButton.Click
Sub
OnClick Handles aButton.Click

Option Infer

Using Option Infer lets you specify whether VB should enforce type declarations for your types. While setting Option Infer On may allow for quicker development, it may lead to maintenance challenges down the road.

Option Infer On is the default setting for new projects in VB 2008 and can be changed via Project Properties >> Compile.

Total Pages : 6 23456


        Rate this article Read/Post comments Support Us   Printable Version
 Book Detail
Book Title : Accelerated VB 2008
Author: Guy Fouche and Trey Nash
Publisher: Apress
Price: 39.99 US$
EBook Price: 27.99 US$
Publisher Home Page: http://www.apress.com
Book Url: http://www.apress.com/book/view/1590598741
 Post a new question or comment about this article
Subject:
Comment:
 [Top] Rate this article:-
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
Latest Comments:
Subject Posted By Posted On
Support Us
Tell your friends about us
Is this article is a Bad Submission report us here
Submit articles, tutorials, and tips
Help by answering questions on our discussion forums
Help us correct errors and broken links
Looking for a job? Post your resume here
Looking for developers? Post your job here

6 Months Free & No Setup Fees ASP.NET Hosting!
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.