<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>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # checked(C# 參考) **checked** 關鍵字用于對整型算術運算和轉換顯式啟用溢出檢查。 默認情況下,如果表達式僅包含常數值,且產生的值在目標類型范圍之外,則它會導致編譯器錯誤。如果表達式包含一個或多個非常數值,則編譯器不檢測溢出。在下面的示例中,計算賦給 i2 的表達式不會導致編譯器錯誤。 ``` // The following example causes compiler error CS0220 because 2147483647 // is the maximum value for integers. //int i1 = 2147483647 + 10; // The following example, which includes variable ten, does not cause // a compiler error. int ten = 10; int i2 = 2147483647 + ten; // By default, the overflow in the previous statement also does // not cause a run-time exception. The following line displays // -2,147,483,639 as the sum of 2,147,483,647 and 10. Console.WriteLine(i2); ``` 默認情況下,在運行時也不檢查這些非常數表達式是否溢出,這些表達式不引發溢出異常。上面的示例顯示 -2,147,483,639 作為兩個正整數之和。 可以通過編譯器選項、環境配置或使用 **checked** 關鍵字來啟用溢出檢查。下面的示例演示如何使用 **checked** 表達式或 **checked** 塊,在運行時檢測由前面的求和計算導致的溢出。兩個示例都引發溢出異常。 ``` // If the previous sum is attempted in a checked environment, an // OverflowException error is raised. // Checked expression. Console.WriteLine(checked(2147483647 + ten)); // Checked block. checked { int i3 = 2147483647 + ten; Console.WriteLine(i3); } ``` 可以使用 [unchecked](https://msdn.microsoft.com/zh-cn/library/a569z7k8.aspx) 關鍵字阻止溢出檢查。 此示例演示如何使用 **checked** 啟用運行時溢出檢查。 ``` class OverFlowTest { // Set maxIntValue to the maximum value for integers. static int maxIntValue = 2147483647; // Using a checked expression. static int CheckedMethod() { int z = 0; try { // The following line raises an exception because it is checked. z = checked(maxIntValue + 10); } catch (System.OverflowException e) { // The following line displays information about the error. Console.WriteLine("CHECKED and CAUGHT: " + e.ToString()); } // The value of z is still 0. return z; } // Using an unchecked expression. static int UncheckedMethod() { int z = 0; try { // The following calculation is unchecked and will not // raise an exception. z = maxIntValue + 10; } catch (System.OverflowException e) { // The following line will not be executed. Console.WriteLine("UNCHECKED and CAUGHT: " + e.ToString()); } // Because of the undetected overflow, the sum of 2147483647 + 10 is // returned as -2147483639. return z; } static void Main() { Console.WriteLine("\nCHECKED output value is: {0}", CheckedMethod()); Console.WriteLine("UNCHECKED output value is: {0}", UncheckedMethod()); } /* Output: CHECKED and CAUGHT: System.OverflowException: Arithmetic operation resulted in an overflow. at ConsoleApplication1.OverFlowTest.CheckedMethod() CHECKED output value is: 0 UNCHECKED output value is: -2147483639 */ } ``` ## C# 語言規范 有關詳細信息,請參閱 [C# 語言規范](https://msdn.microsoft.com/zh-cn/library/ms228593.aspx)。該語言規范是 C# 語法和用法的權威資料。 ## 請參閱 [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/x53a06bb.aspx) [Checked 和 Unchecked(C# 參考)](https://msdn.microsoft.com/zh-cn/library/khy08726.aspx) [unchecked(C# 參考)](https://msdn.microsoft.com/zh-cn/library/a569z7k8.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>

                              哎呀哎呀视频在线观看