& 不适用于短路规则
&& 适用于短路规则
例子 :
下面的例子最能说明问题
// cs_operator_logical_and.cs
using System;
class Test


{
static bool fn1()

{
Console.WriteLine("fn1 called");
return false;
}

static bool fn2()

{
Console.WriteLine("fn2 called");
return true;
}

public static void Main()

{
Console.WriteLine("regular AND:");
Console.WriteLine("result is {0}", fn1() & fn2());
Console.WriteLine("short-circuit AND:");
Console.WriteLine("result is {0}", fn1() && fn2());
}
}
输出:
regular AND:
fn1 called
fn2 called
result is False
short-circuit AND:
fn1 called
result is False
fn1 called
fn2 called
result is False
short-circuit AND:
fn1 called
result is False
PS.
(|) 与 (||) 运算符也是一样的道理