简体   繁体   English

运算符'=='不能应用于'方法组'类型的操作数

[英]Operator '==' cannot be applied to operand of type 'method group'

I have following function which returns true or false : 我有以下函数返回truefalse

public bool ValidateURL()
{
   if (string.IsNullOrEmpty(txt22.Text) & string.IsNullOrEmpty(txt33.Text))
   {
      return false;
   }
   else 
   {
      return true;
   }
}

Now following code is on a button but I am getting " Operator cannot be applied " error: 现在下面的代码在按钮上,但我得到“ 操作员无法应用 ”错误:

private void btn33_Click(object sender, EventArgs e)
{
   if (ValidateURL==true)
   {
      MessageBox.Show("Enter data");
   }
}

How can i fix it? 我该如何解决?

private void btn33_Click(object sender, EventArgs e)
{
    if (ValidateURL())
    {
        MessageBox.Show("Enter data");
    }
}

EDIT: 编辑:

As Cody Gray pointed out, there's no real point in comparing "true" and the value returned by ValidateURL() ( ValidateURL() == true ). 正如Cody Gray指出的那样,比较“true”和ValidateURL()返回的值( ValidateURL() == true )没有实际意义。 Nobody really does it and it just makes the code longer. 没有人真正做到这一点,它只会使代码更长。 When I answered the question, I just quickly copied, pasted and fixed OP's problem and this is why the comparison was there. 当我回答这个问题时,我只是快速复制,粘贴并修复了OP的问题,这就是比较的原因。 While absolutely valid, it's not really needed. 虽然绝对有效,但并不是真的需要它。 +1 Cody. +1科迪。

将其更改为:

if (ValidateURL())

Change 更改

if (ValidateURL==true)

to

if (ValidateURL() ==true)

You need parentheses. 你需要括号。 Should be ValidateURL() == true 应该是ValidateURL() == true

你要

if (ValidateURL() == true)

A Google search of this error led me here. 谷歌搜索这个错误导致我在这里。 In my case, it was because I was referencing a new property in an ASP.NET MVC Razor page. 就我而言,这是因为我在ASP.NET MVC Razor页面中引用了一个新属性。 The property had been added to my model, but I had forgotten to compile the project. 该属性已添加到我的模型中,但我忘记编译该项目。 The Razor compiler couldn't find the property, and was assuming I was trying to reference an extension method. Razor编译器找不到属性,并假设我试图引用扩展方法。

Once I compiled, the error cleared up. 编译完成后,错误就消失了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 接线员'?'不能应用于'方法组'类型的操作数 - Operator '?' cannot be applied to operand of type 'method group' 运算符“!” 不能应用于“方法组”类型的操作数 - 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