Remove all the elements that match the conditions defined by the specified predicate in CSharp
Description
The following code shows how to remove all the elements that match the conditions defined by the specified predicate.
Example
using System;//from ww w . ja va2s. c o m
using System.Collections;
using System.Collections.Generic;
class Sample
{
public static void Main()
{
List<string> words = new List<string>();
words.Add("A");
words.Add("HTML");
words.Add("HTML5");
words.Add("XML");
words.Add("E");
words.Add("F");
foreach(String s in words){
Console.WriteLine(s);
}
words.RemoveAll(s => s.StartsWith("H"));
foreach(String s in words){
Console.WriteLine(s);
}
}
}
The code above generates the following result.