Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

.net

I have following function which returns true or 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?

like image 251
Susan Moty Avatar asked Apr 08 '11 13:04

Susan Moty


1 Answers

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). 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. While absolutely valid, it's not really needed. +1 Cody.

like image 106
Piotr Justyna Avatar answered Oct 26 '22 15:10

Piotr Justyna