473,387 Members | 1,578 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Predicate in Net 3.5

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
Nov 24 '07 #1
1 1153
You are probably meaning lambda expressions and LINQ?
http://blogs.msdn.com/vbteam/archive...ion-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
--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net

"shapper" <md*****@gmail.comwrote in message
news:ed**********************************@s8g2000p rg.googlegroups.com...
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

Nov 24 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: hall | last post by:
I accidently overloaded a static member function that I use as predicate in the std::sort() for a vector and ended up with a compiler error. Is this kind of overload not allowed for predicates and...
5
by: matthias_k | last post by:
Hi, I need to sort elements of a std::list using a function predicate, something like: bool predicate( const& M m1, const& M m2 ) { return m1.somedata < m2.somedata; } I tried to call...
2
by: Marco Segurini | last post by:
Hi, I have written the following code: // start code using System; using System.Collections.Generic; using System.Text; namespace MyPredicates
5
by: Peter Olcott | last post by:
I created an object that requires access to another objects data, yet have found no good way to pass this data as a parameter because the member function that requires this data must be a binary...
5
by: Andrew Robinson | last post by:
Any easy answer what is wrong here? private List<string> BodyWords = new List<string>(); string word = "Andrew"; the following causes a compilation error:
3
by: BG | last post by:
Here's my program. { array<Byte> ^buffer = // something int length = Array::FindIndex(buffer, gcnew Predicate<Byte>(&MyClass::isChar13) ); ... } bool MyClass::isChar13(Byte b)
8
by: Jeff S. | last post by:
I was recently advised: << Use List<struct> and Find() using different Predicate delegates for your different search needs.>> What is "Predicate delegate" as used in the above recommendation? ...
2
by: =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?= | last post by:
Hello guys, I was wondering if it was possible to reference a boolean predicate in a variable. Basically I want to do with the boolean predicate what you would do with any other variable; I want...
5
by: Ganesh | last post by:
hi ! Can the predicate function used in std::sort take optional arguments ? For instance. I have a class Point. I create a vector of this and then want to compare the slopes of these points with...
8
by: thomas | last post by:
priority_queue usually uses the greater<intpredicate function. But as you know, we don't always use priority_queue<int>. Actually we may need the "priority_queue<pair<int,int>,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.