当我键入一个LINQ查询,智能感知在Visual Studio 2010中显示,where子句预计<条件>。正如
从anItem在listOfItems其中...智能感知显示,预计A<条件>
这是什么<条件>指什么?它是一个类型?一个predicate?一个布尔EX pression?举例来说,如果你输入...
listOfItems.RemoveAll(
...智能感知表明,它正在期待一个 predicate 。什么是模拟的&所述;条件>在LINQ? (我得到怎样的使用 WHERE条件,我想知道这是什么意思)。从长远来看,我想开始编写复杂的where子句,想要了解LINQ实际上是在做/期望,所以我可以明白是怎么回事。
我已经绕了一点,但没有我发现在MSDN上一派似乎适合:
http://msdn.microsoft.com/en-us /library/ms606907.aspx (似乎是错误的)
http://msdn.microsoft.com/en-us /library/7szfhaft.aspx (似乎是错误的)
解决方案据pretty的简单,只是要求一个布尔EX pression可以为每个 anItem 在查询前pression。
的第一款where子句(C#参考)总结道起来很好:
在其中,
子句在查询中使用EX pression到指定数据源元素将在查询前pression返回。它采用一个布尔条件( predicate 的),每个源元素(由一系列变量引用),并返回那些为其指定条件为真。一个查询EX pression可以包含多个其中,
子句和一个子句可以包含多个predicate SUBEX pressions。
这是什么 Where子句(Visual Basic中)说:
的条件的
必需。一名前pression,用于确定集合中的当前项目的值是否包含在输出集合。这位前pression结果必须为布尔
值或布尔
价值相等。如果条件计算结果为真
,该元素包含在查询结果;否则,该元素被排除在查询结果
When I type a LINQ query, intellisense in Visual Studio 2010 shows that the where clause expects < condition > . As in
From anItem in listOfItems where ... Intellisense shows it expects a < condition >
What does this < condition > refer to? Is it a type? A predicate? A boolean expression? For instance, if you type...
listOfItems.RemoveAll(
...intellisense shows that it is expecting a predicate. What is the analog for a < condition > in linq? (I get how to use a where condition, I want to know what it means). In the long run, I want to start writing complex where clauses and want to understand what LINQ is actually doing/expecting so I can understand what is going on.
I've googled around a little but nothing I find on msdn seems to fit:
http://msdn.microsoft.com/en-us/library/ms606907.aspx (seems wrong)
http://msdn.microsoft.com/en-us/library/7szfhaft.aspx (seems wrong)
解决方案It pretty much just asks for a Boolean expression that can be evaluated for every anItem
in your query expression.
The first paragraph of where clause (C# Reference) sums it up nicely:
The where
clause is used in a query expression to specify which elements from the data source will be returned in the query expression. It applies a Boolean condition (predicate) to each source element (referenced by the range variable) and returns those for which the specified condition is true. A single query expression may contain multiple where
clauses and a single clause may contain multiple predicate subexpressions.
And this is what Where Clause (Visual Basic) says:
condition
Required. An expression that determines whether the values for the current item in the collection are included in the output collection. The expression must evaluate to a Boolean
value or the equivalent of a Boolean
value. If the condition evaluates to True
, the element is included in the query result; otherwise, the element is excluded from the query result.