How do you do Linq with non-lambda express for the following (which does not work):
string[] words = { "believe", "relief", "receipt", "field" };
var wd = (from word in words
select word).Any(Contains ("believe"));
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It’s not clear what good you believe the
from wor in words select woris doing – it’s really not helping you at all.It’s also not clear why you don’t want to use a lambda expression. The obvious approach is:
Note that this isn’t checking whether the list of words has the word “believe” in – it’s checking whether the list of words has any word containing “believe”. So “believer” would be fine. If you just want to check whether the list contains
believeyou can just use:EDIT: If you really want to do it without a lambda expression, you’ll need to basically fake the work that the lambda expression (or anonymous method) does for you:
Then you can use:
Obviously you really don’t want to do that though…
EDIT: Of course you could use:
But that’s pretty ugly too – I’d definitely use the lambda expression.