开发者

How to write the right linq where clause?

I tr开发者_C百科ied to use linq to get storyboard data in code and try following where clause:

Where(
   delegate (abc<VisualStateGroup, VisualState> xyz) 
   { return (xyz.state.Name == "PopupOpened");}
  )

it gave me error:

An anonymous method expression cannot be converted to an expression tree

how to write the right where clause for this case?


Use a lambda:

Where(xyz => xyz.state.Name == "PopupOpened");


Just use a lambda expression:

.Where( xyz => xyz.state.Name == "PopupOpened" );

If you don't need the operation as an expression tree, you can also write this as an anonymous delegate, but it would be more verbose.

As @itowlson says, if you are using this in a context where an expression tree is expected, you must supply a lamda, as only lambdas can be converted into expression trees - anonymous delegates cannot.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜