2

I have an array string[] data with 512 items. Can I use LINQ to find all elements that contain the string "tx"?

I did try data.Where but it was not a valid statement.

2
  • Where() expects a delegate/lambda expression. Commented Sep 8, 2011 at 12:33
  • you are right. I need lambda expression. Commented Sep 8, 2011 at 12:35

3 Answers 3

5

Simple:

data.Where(s => s.Contains("tx"))
Sign up to request clarification or add additional context in comments.

Comments

3

Make sure you have using System.Linq; at the top of your file. data.Where should work just fine.

And you need to be using .NET 3.5 or above.

If you have this, then Jons answer should work perfectly.

Comments

3

WHERE should work fine!

 var filtered = data.Where(x => x.Contains("tx"));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.