' Visual Basic 2008 9.0 .NET Examples - Query Methods - New in Visual Basic 2008 - 9.0 : Option Strict On Option Infer On Public Class Counter Private m_Value As Integer Public Property Value() As Integer Get Value = m_Value End Get Set(ByVal value As Integer) m_Value = value End Set End Property End Class Public Module MyEnumerable _ Public Function GetWhere(Of T)(ByVal source As IEnumerable(Of T), _ ByVal predicate As Func(Of T, Boolean)) _ As IEnumerable(Of T) Dim getWhereList As New List(Of T) For Each item As T In source If predicate.Invoke(item) Then getWhereList.Add(item) End If Next GetWhere = getWhereList End Function End Module Public Class Example1 Public Shared Sub Main() Dim source = New Counter() {New Counter With {.Value = 10}, _ New Counter With {.Value = 20}, _ New Counter With {.Value = 30}} Dim predicate As Func(Of Counter, Boolean) = _ Function(counter) counter.Value > 15 Dim query1 = MyEnumerable.GetWhere(source, predicate) ' (1) For Each counter As Counter In query1 Console.WriteLine(counter.Value) Next Console.WriteLine() ' Dim query2 = source.GetWhere(Function(counter) counter.Value < 25) ' (2) For Each counter As Counter In query2 Console.WriteLine(counter.Value) Next ' Console.ReadLine() End Sub End Class ' Visit www.studyvb.com for more examples. Copyright 2003-2008 De Wolf.