|
이 문서는 기계로 번역한 것입니다. 원본 텍스트를 보려면 포인터를 문서의 문장 위로 올리십시오. 추가 정보
|
번역
원본
|
&& 연산자(C# 참조)
Visual Studio 2012
class LogicalAnd { static void Main() { // Each method displays a message and returns a Boolean value. // Method1 returns false and Method2 returns true. When & is used, // both methods are called. Console.WriteLine("Regular AND:"); if (Method1() & Method2()) Console.WriteLine("Both methods returned true."); else Console.WriteLine("At least one of the methods returned false."); // When && is used, after Method1 returns false, Method2 is // not called. Console.WriteLine("\nShort-circuit AND:"); if (Method1() && Method2()) Console.WriteLine("Both methods returned true."); else Console.WriteLine("At least one of the methods returned false."); } static bool Method1() { Console.WriteLine("Method1 called."); return false; } static bool Method2() { Console.WriteLine("Method2 called."); return true; } } // Output: // Regular AND: // Method1 called. // Method2 called. // At least one of the methods returned false. // Short-circuit AND: // Method1 called. // At least one of the methods returned false.