Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / November 2007

Tip: Looking for answers? Try searching our database.

Predicate in Net 3.5

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
shapper - 24 Nov 2007 02:45 GMT
Hello,

I have a List(Of MyClass).
MyClass has two properties: Name and City.

I want to find, without using a loop, if there is a item where name =
NameParameter.

I know that I can use a Predicate but in .NET 2.0 Predicates do not
accepted Parameters.

Because of that I used a Predicate Wrapper.

With .NET 3.5 I know this has changed and now it is much easier to do
something like this.

However, I can't find any example of it.

Can someone, please, help me out?

Thanks,
Miguel
Teemu Keiski - 24 Nov 2007 16:28 GMT
You are probably meaning lambda expressions and LINQ?
http://blogs.msdn.com/vbteam/archive/2007/09/11/lambda-expressions-and-expressio
n-trees.aspx


Here's an example

Public Class MySampleClass

   Public Sub New(ByVal Name As String, ByVal City As String)
       Me.Name = Name
       Me.City = City
   End Sub

   Private _name As String
   Private _city As String

   Public Property Name() As String
       Get
           Return _name
       End Get
       Set(ByVal value As String)
           _name = value
       End Set
   End Property

   Public Property City() As String
       Get
           Return _city
       End Get
       Set(ByVal value As String)
           _city = value
       End Set
   End Property

End Class

Dim l As New List(Of MySampleClass)
       l.Add(New MySampleClass("Karl", "NY"))
       l.Add(New MySampleClass("Mike", "NY"))
       l.Add(New MySampleClass("Lars", "LA"))

       Dim lookingFor As String = "NY"

       Dim guys = From person In l _
                  Where person.City = lookingFor _
                   Select person

       For Each p As MySampleClass In guys
           Response.Write(p.Name)
       Next

Signature

Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net

> Hello,
>
[quoted text clipped - 18 lines]
> Thanks,
> Miguel

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.