<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # || 運算符(C# 參考) 條件或運算符 (**||**) 執行的邏輯或其 **bool** 操作數。如果第一個操作數計算結果為 **true**,第二個操作數對象不會計算。如果第一個操作數計算結果為 **false**,第二個運算符確定或表達式整體是否計算結果為 **true** 或 **false**。 ## 備注 操作 ``` x || y ``` 對應于操作 ``` x | y ``` 但,如果 x 是 **true**,y 不會計算無論 y,的值,因為或操作是 **true**。此概念稱為“短路計算”。 條件或運算符無法重載,但是,公共邏輯運算符和 [真](https://msdn.microsoft.com/zh-CN/library/eahhcxk2.aspx) 和 [假](https://msdn.microsoft.com/zh-CN/library/67bxt5ee.aspx) 運算符的重載,有一些限制的,也將條件邏輯運算符的重載。 在下面的示例中,表達式中使用的 **||** 計算只有第一個操作數。使用的表達式**|**計算兩個操作數。在第二個示例中,因此,如果兩個操作數計算,則運行時會發生異常。 ``` class ConditionalOr { // Method1 returns true. static bool Method1() { Console.WriteLine("Method1 called."); return true; } // Method2 returns false. static bool Method2() { Console.WriteLine("Method2 called."); return false; } static bool Divisible(int number, int divisor) { // If the OR expression uses ||, the division is not attempted // when the divisor equals 0. return !(divisor == 0 || number % divisor != 0); // If the OR expression uses |, the division is attempted when // the divisor equals 0, and causes a divide-by-zero exception. // Replace the return statement with the following line to // see the exception. //return !(divisor == 0 | number % divisor != 0); } static void Main() { // Example #1 uses Method1 and Method2 to demonstrate // short-circuit evaluation. Console.WriteLine("Regular OR:"); // The | operator evaluates both operands, even though after // Method1 returns true, you know that the OR expression is // true. Console.WriteLine("Result is {0}.\n", Method1() | Method2()); Console.WriteLine("Short-circuit OR:"); // Method2 is not called, because Method1 returns true. Console.WriteLine("Result is {0}.\n", Method1() || Method2()); // In Example #2, method Divisible returns True if the // first argument is evenly divisible by the second, and False // otherwise. Using the | operator instead of the || operator // causes a divide-by-zero exception. // The following line displays True, because 42 is evenly // divisible by 7. Console.WriteLine("Divisible returns {0}.", Divisible(42, 7)); // The following line displays False, because 42 is not evenly // divisible by 5. Console.WriteLine("Divisible returns {0}.", Divisible(42, 5)); // The following line displays False when method Divisible // uses ||, because you cannot divide by 0. // If method Divisible uses | instead of ||, this line // causes an exception. Console.WriteLine("Divisible returns {0}.", Divisible(42, 0)); } } /* Output: Regular OR: Method1 called. Method2 called. Result is True. Short-circuit OR: Method1 called. Result is True. Divisible returns True. Divisible returns False. Divisible returns False. */ ``` ## 請參閱 [C# 參考](https://msdn.microsoft.com/zh-CN/library/618ayhy6.aspx) [C# 編程指南](https://msdn.microsoft.com/zh-CN/library/67ef8sbd.aspx) [C# 運算符](https://msdn.microsoft.com/zh-CN/library/6a71f45d.aspx)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看