I\'m trying to brush up on my LINQ by writing some simple extension methods. Is there any better way to write such a function as below that removes a given list of character
I would prefer the first form with extension methods though simplified to
public static string Remove(this string s, IEnumerable chars)
{
return new string(s.Where(c => !chars.Contains(c)).ToArray());
}
As for select keyword, it's obligatory in second form. The documentation says what "A query expression must terminate with either a select clause or a group clause". That's why I would avoid LINQ syntactic sugar.