Tuesday, December 25, 2007

Illustrating what we know for ages

Something Silly....
I was once asked to illustrate something which we know from time we all started coding ,to prove for an short circuit statement of format x op y, y is evaluated only if its meaningful and that x is alway evaluated before y.

One simple way to prove it was to write a function

static bool Check(bool Param)
{
Console.WriteLine(Param.ToString());
return Param;
}
static void Main(string[] args)
{
if(Check(true) && Check(false))
{
}

Console.WriteLine("*********");

if(Check(false) && Check(true))
{
}
Console.ReadLine();
}



Following Output was generated proving the needful

True
False
*********
False