In C#, given the two methods
bool Action1(object Data);
bool Action2(object Data);
that are used in an if
statement like this:>
No, C# support logical short-circuiting so if Action1
returned true
it would never evaluate Action2
.
This simple example shows how C# handles logical short-circuiting:
using System;
class Program
{
static void Main()
{
if (True() || False()) { } // outputs just "true"
if (False() || True()) { } // outputs "false" and "true"
if (False() && True()) { } // outputs just "false"
if (True() && False()) { } // outputs "true" and "false"
}
static bool True()
{
Console.WriteLine("true");
return true;
}
static bool False()
{
Console.WriteLine("false");
return false;
}
}