Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I have an array string[] data with 512 items. Can I use LINQ to find all elements that contain the string "tx"?
string[] data
"tx"
I did try data.Where but it was not a valid statement.
data.Where
Where()
Simple:
data.Where(s => s.Contains("tx"))
Add a comment
Make sure you have using System.Linq; at the top of your file. data.Where should work just fine.
using System.Linq;
And you need to be using .NET 3.5 or above.
If you have this, then Jons answer should work perfectly.
WHERE should work fine!
WHERE
var filtered = data.Where(x => x.Contains("tx"));
Required, but never shown
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.
Explore related questions
See similar questions with these tags.
Where()expects a delegate/lambda expression.