This may be stupid.but i have a simple doubt Suppose i have the following check in a function
bool Validate(string a , string b)
{
if(a == null || b == null)
In boolean expressions (rather than integers etc), the main difference is: short-circuiting. ||
short-circuits. |
does not. In most cases you want short-circuiting, so ||
is much much more common. In your case, it won't matter, so ||
should probably be used as the more expected choice.
The times it matters is:
if(politics.IsCeasefire() | army.LaunchTheRockets()) {
// ...
}
vs:
if(politics.IsCeasefire() || army.LaunchTheRockets()) {
// ...
}
The first always does both (assuming there isn't an exception thrown); the second doesn't launch the rockets if a ceasefire was called.