2

i have:

List<string> MyFiles

i need to delete everything from this list that has a specific string inside of it

for example if the list was:

alex1
alex123
alex234
alex345

and i would like to delete every element in this list that has the string "1" in it?

2
  • 1
    Are you sure linq-to-sql is appropriate? Barring further info, this is an in-memory collection. Commented Apr 4, 2011 at 16:39
  • it can be done any way i dont care Commented Apr 4, 2011 at 16:39

2 Answers 2

8
MyFiles.RemoveAll(s => s.Contains("1"));
Sign up to request clarification or add additional context in comments.

Comments

1

Does this work for you?

C#

MyFiles.RemoveAll((string s) => s.Contains("1"))

I code in VB.NET:

MyFiles.RemoveAll(Function(s As String) s.Contains("1"))

1 Comment

Sorry for the seemingly duplicate answer, there were no answers when I clicked the link. I had to go and convert the VB to C#, came back, posted, and there was the answer already.

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.