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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With