Is it a good practice to call a method that returns true or false values in an if statement?
Something like this:
private void VerifyAccount()
{
if (!ValidateCredentials(txtUser.Text, txtPassword.Text))
{
MessageBox.Show("Invalid user name or password");
}
}
private bool ValidateCredentials(string userName, string password)
{
string existingPassword = GetUserPassword(userName);
if (existingPassword == null)
return false;
var hasher = new Hasher { SaltSize = 16 };
bool passwordsMatch = hasher.CompareStringToHash(password, existingPassword);
return passwordsMatch;
or is it better to store them in a variable then compare them using if else values like this
bool validate =ValidateCredentials(txtUser.Text, txtPassword.Text);
if(validate == false){
//Do something
}
I am not only referring to .NET, I am referring to the question in all programming languages it just so happens that I used .NET as an example

if (!validate)rather thanif (validate == false). – Philip Feb 25 '12 at 18:01IsValidCredentials, although grammatically awkward, is a common format for indicating a boolean return value. – zzzzBov Feb 25 '12 at 20:41!is the "NOT" operator, it negates any boolean expression. Soif (!validate)is the opposite ofif (validate). The if statement will be entered ifvalidateis not true. – Philip Feb 26 '12 at 13:53