简体   繁体   English

运算符“!” 不能应用于“方法组”类型的操作数

[英]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.

相关问题 接线员'?'不能应用于'方法组'类型的操作数 - Operator '?' cannot be applied to operand of type 'method group' 运算符&#39;==&#39;不能应用于&#39;方法组&#39;类型的操作数 - Operator '==' cannot be applied to operand of type 'method group' “。” 运算符不能应用于类型为“方法组”(CS0023)(CurrencyConverter.Droid)的操作数 - The `.' operator cannot be applied to operand of type `method group' (CS0023) (CurrencyConverter.Droid) 运算符 &lt; 不能应用于“方法组”类型的操作数 - Operator < cannot be applied to operands of type "method group" 错误1运算符&#39;&gt; =&#39;不能应用于类型为&#39;方法组&#39;和&#39;方法组&#39;的操作数 - Error 1 Operator '>=' cannot be applied to operands of type 'method group' and 'method group' 运算符“ ==”不能应用于“方法组”和“方法组”类型的操作数 - Operator `==' cannot be applied to operands of type `method group' and `method group' 错误:操作员&#39;!&#39; 不能应用于&#39;int&#39;类型的操作数 - Error: Operator '!' cannot be applied to operand of type 'int' 接线员&#39;?&#39; 不能应用于&#39;T&#39;类型的操作数(2) - Operator '?' cannot be applied to operand of type 'T' (2) 接线员&#39;!&#39; 不能应用于x类型的操作数 - Operator '!' cannot be applied to operand of type x 运算符“ ”不能应用于类型的操作数<int>和空 - Operator ' ' cannot be applied to operand of type <int> and null
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM