Can someone explain me why this string extended method gives me an ArgumentOutOfRangeException (Index and count must refer to a location within the string. Parameter name: count),
public static string Remove(this string str, char lower, char upper)
{
return str.Where(ch => ch <= upper && ch >=lower)
.Aggregate(string.Empty, (current, ch) => current + ch);
}
while a method does not.
private string Remove(string str, char lower, char upper)
{
return str.Where(ch => ch <= upper && ch >= lower)
.Aggregate(string.Empty, (current, ch) => current + ch);
}