This tutorial was created with Visual Studio .NET 2008, but the results can be achieved in 2005 if Microsoft's LINQ Community Technology Preview release is downloaded and installed from Microsoft.
In this tutorial, we will be looking at VB.NET Lambda Expressions. We will see how we can sort data from an array using the newly-introduced Lambda Expressions in VB.NET. Lambda Expressions can be used in place of LINQ Queries, and can make the code a lot shorter. In this example, we will be creating an array and retrieving data from the array depending on user entry. We will create an array of names, then retrieve only the ones that start with a certain letter.
We will be creating this example in a Windows Form. We will have one textbox for data input, one button to initiate the call, and one label to display the output. Once we have these controls on our form, we can begin coding. We can code everything into our OnClick button event.
First, we will initialize the string array. Then we can add the FOR loop to display our selection:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim arrNames() As String = {"Mike", "Zach", "Ella", "Eli", "Jo"}
For Each varName In arrNames.Where(Function(n) n.StartsWith(TextBox1.Text))
Label2.Text = Label2.Text + varName & ", "
Next varName
End Sub
The string is defined and some names are added to it. We then initialize a FOR loop and select the data we want: this Lambda Expression is selecting all the names within the array that begin with the text that was submitted to the textbox - if nothing is entered, everything will be returned and displayed.
Please follow the link to Linqhelp.com for the continuation and code. Thanks and happy coding!!
- Related Articles
- Related Q&A




Finding Long-Lasting Cell Phone Skins For Your Blackberry Model
By: BhratBrij | 01/01/2010If you are going on the Internet to look for places where you can get cell phone skins , which are made-to-measure, you can get customized Blackberry Tour skins, Blackberry Pearl skins, and Blackberry Curve skins quite easily there.
Know more about compact flash 16gb
By: philipwots | 31/12/2009It is almost a known fact that compact flash 16gb is a mass storage device format which is used in portable electronic devices in the market.
Pass4side 000-111 exam questions
By: Adela1987 | 30/12/2009Pass4side 000-111 Exam Resources include Questions and Answers, Practice Testing Software, Stud Guides, Audio Learning and Preparation Labs. These IBM 000-111 Exam Preparation Materials will make you provide the accurate answers of real 000-111 exam questions. With our Exam Resources you can test your knowledge and readiness for exam, assess your performance in a given time, get scores and highlighted weaknesses with suggestions to improve the weak areas.
8 GB USB DRIVE
By: Phillip Roth | 29/12/2009USB flash drive consists of a small printed circuit board carrying the circuit elements and a USB connector insulated electrically and protected inside a plastic, metal, or rubberized case which can be carried in a pocket.
Support Information About AA Online
By: Ed Philips | 26/12/2009Discover how to quit drinking as revealed in Ed Philips "Alcoholics Anonymous Online" support guide, which offers tried and tested alcoholic addiction methods to quit drinking within 21 days.
Know the information USB sticks
By: John Milton | 24/12/2009Now in the market there is high demand of usb sticks among its users. Seeing this the producers of usb sticks now focussing more on its reliability.
A Photography Course For All The Family
By: Dan Feildman | 23/12/2009Excellent Digital Photography Courses Introducing Free Digital Photography Guide called "How To Take Beautiful Digital Pics Made Simple". The latest tips on how to use a digital camera like a pro.
Reinforce Database Management with Remote DBA
By: Kashif Mukhtar | 23/12/2009Databases are the foundation of the digital economy. They store the information that run businesses and organize the vast amount of data that is created on a regular basis. Even though e-business infrastructures are requiring stronger database support to sustain their 24x7 operations, shrinking IT budgets are forcing companies to reduce the size of their DBA staff. With databases growing in size and complexity, the role of the already overburdened DBA is becoming increasingly difficult.
Using Linq to Objects in C#
By: LinqHelp | 24/09/2008 | DatabasesIn this tutorial, we will be looking at using LINQ to Objects. We will be creating a Windows Forms Application that will first define an array of numbers, and then we will use LINQ to Objects to interact with this collection of numbers.
Creating Linq to Sql Entities in Vb.net
By: LinqHelp | 15/09/2008 | DatabasesThis tutorial will show how we can bypass the Designer and write the class ourselves, so that we get a better understanding of what's going on. For this example, we will be using a SQL database with one table and three columns - id, name, and city.
Creating Linq to Sql Entities in C#
By: LinqHelp | 15/09/2008 | DatabasesThis tutorial will show how we can bypass the Designer and write the class ourselves, so that we get a better understanding of what's going on. For this example, we will be using a SQL database with one table and three columns - id, name, and city.
Linq Projection in C#
By: LinqHelp | 19/08/2008 | DatabasesIn this tutorial we will look at LINQ Projection (C#), which is when we can select specific data from a source without retrieving all fields. We will be creating a class to define a list in which we will create a number of people with IDs, names and cities. Then we will use buttons to select only parts of this data.
Linq Projection in Vb
By: LinqHelp | 19/08/2008 | DatabasesIn this tutorial we will look at LINQ Projection, which is when we can select specific data from a source without retrieving all fields. We will be creating a class to define a list in which we will create a number of people with IDs, names and cities. Then we will use buttons to select only parts of this data.
Linq Lambda Expressions in Vb.net - Querying Data
By: LinqHelp | 12/08/2008 | DatabasesIn this tutorial, we will be looking at VB.NET Lambda Expressions. We will see how we can sort data from an array using the newly-introduced Lambda Expressions in VB.NET. Lambda Expressions can be used in place of LINQ Queries, and can make the code a lot shorter.