[英]Operator '==' cannot be applied to operand of type 'method group'
I have following function which returns true
or false
: 我有以下函数返回
true
或false
:
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.