Prev | Current Page 39 | Next

Guy Fouch?©, Trey Nash

"Accelerated VB 2008"

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
CHAPTER 1 n VB 2008 OVERVIEW 8
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:
_
Public Function IsTickerValid(ByVal aTicker As String) As Boolean
Dim ValidTicker As Boolean = True
If aTicker.


Pages:
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
śmieszne dowcipy basen z piłeczkami dieta light życzenia ślubne Connie Talbot