473,396 Members | 2,151 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,396 software developers and data experts.

Are predicates worth it?

I've been looking at predicate delegates in connection with List<Tsearch
methods. My initial reaction is that the mechanism looks cumbersome, to the
point where I'm wondering if it's not just simpler to stick with a foreach
loop.

If I understand List<Tsearch predicates correctly, I'll need to write a
predicate, which is no big deal. But I will also need a member variable to
set the value of the search criteria that the predicate uses.

In other words, if my search criteria is fixed (like the 'ends in -saurus'
example in MSDN), then I only need the predicate. But if I want to create an
'ends in whatever' predicate, I have to create a string member variable to
contain the 'ends in' criteria that is to be used for the search. The
predicate uses the value of the member variable to make its comparison.

Here's my question: Is it worth it? What do I gain over writing a method
with a simple foreach loop to do the search? Thanks.

--
David Veeneman
Foresight Systems
Aug 8 '06 #1
1 1204
Guess it just depends on which you prefer:

private List<stringEndsIn(List<stringlist, string value)
{
// Using FindAll predicate
return list.FindAll(delegate(string s)
{
return s.EndsWith(value);
});
}

private List<stringEndsIn2(List<stringlist, string value)
{
// Using Foreach
List<stringlist2 = new List<string>();
foreach ( string s in list )
{
if ( s.EndsWith(value) )
list2.Add(s);
}
return list2;
}

--
William Stacey [MVP]

"David Veeneman" <da****@nospam.com (domain is my last name)wrote in
message news:e%***************@TK2MSFTNGP03.phx.gbl...
| I've been looking at predicate delegates in connection with List<Tsearch
| methods. My initial reaction is that the mechanism looks cumbersome, to
the
| point where I'm wondering if it's not just simpler to stick with a foreach
| loop.
|
| If I understand List<Tsearch predicates correctly, I'll need to write a
| predicate, which is no big deal. But I will also need a member variable to
| set the value of the search criteria that the predicate uses.
|
| In other words, if my search criteria is fixed (like the 'ends in -saurus'
| example in MSDN), then I only need the predicate. But if I want to create
an
| 'ends in whatever' predicate, I have to create a string member variable to
| contain the 'ends in' criteria that is to be used for the search. The
| predicate uses the value of the member variable to make its comparison.
|
| Here's my question: Is it worth it? What do I gain over writing a method
| with a simple foreach loop to do the search? Thanks.
|
| --
| David Veeneman
| Foresight Systems
|
|
Aug 8 '06 #2

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

Similar topics

2
by: Thong Nguyen | last post by:
I wrote my own Predicate class for .NET 1.1 which allowed composite predicates using operator overloading... for example: Predicate p1 = {...}; Predicate p2 = {...}; Predicate p1andp2 =...
0
by: dayzman | last post by:
Hi, M'm writing a program to output the results of transforming logical predicates using deMorgan's. Does anyone know of a library that handles logical predicates? Cheers, Michael
2
by: Praveen | last post by:
Hi, Hi I am a newbie in DB2 and Mainframe.I would like to know if there is any diffence between the Quantified Predicates: IN , ANY, and SOME. Thank you very much for your valuable time. ...
1
by: Trent Buck | last post by:
I'm trying to find CPP predicates that allow conditional compilation based on the compiler's standard / features / extensions. So far I have determined that, for GCC, - __STRICT_ANSI__ implies...
2
by: Markus Neifer | last post by:
Hi, i've read that 'Col BETWEEN expr1 and expr2' became stage 1 and indexable in DB2 UDB for z/OS Version 8. Is there any way to find out which predicates are stage 1 and indexable in V7/V8? ...
5
by: Altu | last post by:
Hi all, What does something like mean in an XPath query like /c/d ? If I am not wrong, /c/d means return all d elements that their parent is c and their grand parent is the root element and...
7
balabaster
by: balabaster | last post by:
Okay, after having bashed my head against this long enough I thought of you guys... I thought having exhausted just about every other .NET concept I would come back to predicates because Microsoft's...
0
by: raylopez99 | last post by:
Inspired by Jon, I did a demo prorgram showing three ways to declare predicates, in for example the "FindIndex" and "FindLastIndex" methods of Lists, but in general you can do this for any...
4
by: Arun Srinivasan | last post by:
Hi I was using a query previously, that was efficient select * from table where pred1 and pred2 and pred3; Later I was asked to introduce new ones, but they were not based on table columns but...
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
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.