What is this behaviour called?
I have the following method:
public override bool IsSatisfiedBy(SourceFile candidate)
{
Console.WriteLine("Check 1: " + One.IsSatisfiedBy(candidate));
开发者_如何学运维Console.WriteLine("Check 2: " + Two.IsSatisfiedBy(candidate));
Console.WriteLine("Check 3: " + Three.IsSatisfiedBy(candidate));
return One.IsSatisfiedBy(candidate) && Two.IsSatisfiedBy(candidate) && Three.IsSatisfiedBy(candidate);
}
If i pass a SourceFile as an argument that not fulfills rule one, then rule two and three aren't checked. I know that this is the correct way, but I would like to read more about the exact behaviour but I can't find anything because I don't know what this behaviour is called :D
It's called short-circuit evaluation. In C# it happens for the &&
and ||
operators.
It's called short-circuiting of boolean expressions.
See also: http://en.wikipedia.org/wiki/Short-circuit_evaluation
Short circuit evaluation perhaps
It's called short circuit evaluation.
&&
will only continue evaluation if the first condition is true.
||
behaves in a similar manner, if the first part is true, then the remainder will not be evaluated.
Shortcut or short circuit evaluation : http://en.wikipedia.org/wiki/Short-circuit_evaluation
精彩评论