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