Tuesday, December 8, 2009

Short Circuit Evaluation

The below code snippet shows how .NET evaluates expressions in if statement.

-------------------------------

string x = null;
if (!string.IsNullOrEmpty(x) && x.ToString().Equals(""))
Console.WriteLine("True");
else
Console.WriteLine("False");

if (string.IsNullOrEmpty(x) || x.ToString().Equals(""))
Console.WriteLine("True");
else
Console.WriteLine("False");

-------------------------------

Output:
False
True

No comments:

Post a Comment