KentZhou
KentZhou

Reputation: 25583

How to write the right linq where clause?

I tried 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?

Upvotes: 0

Views: 332

Answers (2)

LBushkin
LBushkin

Reputation: 131796

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.

Upvotes: 1

itowlson
itowlson

Reputation: 74842

Use a lambda:

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

Upvotes: 2

Related Questions