Reputation: 165
Probably a duplicate but of the related questions, I've yet to find a solution that works. Trying to count the number of digits up to a a number of character in a string.
Getting the error: '!' cannot be applied to operand of type 'method group'
line.TakeWhile(!Char.IsLetterOrDigit).Count())
Upvotes: 1
Views: 2095
Reputation: 52300
the problem is exactly what the error tells you: you cannot use !
on an function (the Char.IsLetterOrDigit
) - one simple solution is expanding it into a lambda:
line.TakeWhile(c => !Char.IsLetterOrDigit(c)).Count())
Upvotes: 2
Reputation: 125650
You need to use lambda expression instead of method group syntax here:
line.TakeWhile(x => !Char.IsLetterOrDigit(x)).Count())
Upvotes: 2