[英]Operator '!' cannot be applied to operand of type 'method group'
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 aa number of character in a string.
试图计算位数,最多一个字符串中的字符数。
Getting the error: '!' 收到错误:“!” cannot be applied to operand of type 'method group'
不能应用于“方法组”类型的操作数
line.TakeWhile(!Char.IsLetterOrDigit).Count())
您需要在此处使用lambda表达式而不是方法组语法:
line.TakeWhile(x => !Char.IsLetterOrDigit(x)).Count())
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: 在一个函数上(
Char.IsLetterOrDigit
)-一个简单的解决方案是将其扩展为lambda:
line.TakeWhile(c => !Char.IsLetterOrDigit(c)).Count())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.