C#3.0 predicate in Linq

G

Guest

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
 
M

Michael Nemtsev

Hello Peter,

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

P> Hi folks,
P> I have one code snippet as below: (C#3)
P> var numbers = new int[] {0, 1, 2, 3, 4, 5, 6}
P> var evenNumbers = select p in numbers where (p % 2) == 0 select p;
P> In the above example, what is the predicate? Thanks.
P> Peter
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 Nietzsch
 
J

Jon Skeet [C# MVP]

Peter said:
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;
 
F

Frans Bouma [C# MVP]

Michael said:
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
P> Hi folks,
P> I have one code snippet as below: (C#3)
P> var numbers = new int[] {0, 1, 2, 3, 4, 5, 6}
P> var evenNumbers = select p in numbers where (p % 2) == 0 select p;
P> In the above example, what is the predicate? Thanks.
P> Peter
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#)
------------------------------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top