473,473 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

C#3.0 predicate in Linq

Hi folks,
I have one code snippet as below: (C#3)

var numbers = new int[] {0, 1, 2, 3, 4, 5, 6}
var evenNumbers = select p in numbers where (p % 2) == 0 select p;
In the above example, what is the predicate? Thanks.

Peter
Oct 23 '06 #1
3 1758
Hello Peter,

"==" is the predicate . the same meaning as the SQL predicates - "like",
"between" and etc.

PHi folks,
PI have one code snippet as below: (C#3)
Pvar numbers = new int[] {0, 1, 2, 3, 4, 5, 6}
Pvar evenNumbers = select p in numbers where (p % 2) == 0 select p;
PIn the above example, what is the predicate? Thanks.
PPeter
P>
---
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Oct 23 '06 #2
Peter <Pe***@discussions.microsoft.comwrote:
Hi folks,
I have one code snippet as below: (C#3)

var numbers = new int[] {0, 1, 2, 3, 4, 5, 6}
var evenNumbers = select p in numbers where (p % 2) == 0 select p;
In the above example, what is the predicate? Thanks.
"(p % 2) == 0" is the predicate here - it's the bit which takes a
parameter and determines whether or not the parameter matches the
condition you want.

I'm not entirely sure your example is correct though. It's a while
since I've looked at LINQ, but isn't it more like:

from numbers where (p%2)==0 select p;

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Oct 23 '06 #3
Michael Nemtsev wrote:
Hello Peter,

"==" is the predicate . the same meaning as the SQL predicates -
"like", "between" and etc.
no that are operators.
Predicates are expression which resolve to true or false, e.g.
MyTable.MyField == 3

FB
>
PHi folks,
PI have one code snippet as below: (C#3)
Pvar numbers = new int[] {0, 1, 2, 3, 4, 5, 6}
Pvar evenNumbers = select p in numbers where (p % 2) == 0 select p;
PIn the above example, what is the predicate? Thanks.
PPeter
P---

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Oct 24 '06 #4

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...
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? ...
3
by: cody | last post by:
Hi! It's great that Arrays and List<Tsupport functions that use predicates like TrueForAll(), ConvertAll(), Foreach() and so on. But why are there no such methods for IEnumerable<T>? The...
1
by: shapper | last post by:
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...
5
by: =?Utf-8?B?U2llZ2ZyaWVkIEhlaW50emU=?= | last post by:
Can someone help me convert this to the latest C# syntax using predicate/delegate? You can see my attempt in the comments. Also: how would I set a new font for q_ul? q_ul is a WPF TextBlock and I...
3
by: raylopez99 | last post by:
I suspect the answer to this question is that it's impossible, but how do I make the below code work, at the point where it breaks (marked below). See error CS0411 This is the complete code. ...
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: 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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
1
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

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.