7
检查方法是否返回false:将结果分配给临时变量,还是直接将方法调用置于条件中?
调用在if语句中返回true或false值的方法是一种好习惯吗? 像这样: 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 …