Home » » Need help to use predicate in VB.net

Need help to use predicate in VB.net

Written By M.L on புதன், 10 ஆகஸ்ட், 2011 | ஆகஸ்ட் 10, 2011

I want to use delegate model to search/find values from Generic Collection, Dot net have implemented encapsulated functionality to search for collection.
Following is method signature: -

public Function Find(ByVal match As System.Predicate(Of T)) As T
     Member of: System.Collections.Generic.List(Of T)

Summary:
Searches for an element that matches the conditions defined by the specified predicate, and returns the first occurrence within the entire System.Collections.Generic.List(Of T).

Parameters:
match: The System.Predicate(Of T) delegate that defines the conditions of the element to search for.

Return Values:
The first element that matches the conditions defined by the specified predicate, if found; otherwise, the default value for type T.
Sample piece of code is


                Dim m_tCrossReferenceEntityList As New List(Of String)

                m_tCrossReferenceEntityList.Add("X")
                m_tCrossReferenceEntityList.Add("Y")
                m_tCrossReferenceEntityList.Add("Z")

                ' To find string X from the collection
' m_tCrossReferenceEntityList.Find()

This can be done through looping logic, but would like to understand how does delegate model use to find? And How does predicate work?

0 comments:

கருத்துரையிடுக

Popular Posts

General Category