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

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # false 運算符(C# 參考) 返回[布爾](https://msdn.microsoft.com/zh-cn/library/c8f5xwh7.aspx)值 **true** 以指示操作數為 **false**,否則返回 **false**。 在 C# 2.0 以前,**true** 和 **false** 運算符一直用來創建用戶定義的可以為 null 的值類型,這些值類型與 **SqlBool** 等類型兼容。然而,現在該語言提供對可為 null 的值類型的內置支持,并且應該盡可能地使用它們而不是重載 **true** 和 **false** 運算符。有關更多信息,請參見 [可以為 null 的類型(C# 編程指南)](https://msdn.microsoft.com/zh-cn/library/1t3y8s4s.aspx)。 對于可以為 null 的布爾值,表達式 a != b 不一定等同于 !(a == b),因為兩個值之一或者全部都有可能為 null。必須單獨重載 **true** 和 **false** 運算符,以便正確處理表達式中的 null 值。下面的示例演示如何重載及使用 **true** 和 **false** 運算符。 ``` // For example purposes only. Use the built-in nullable bool // type (bool?) whenever possible. public struct DBBool { // The three possible DBBool values. public static readonly DBBool Null = new DBBool(0); public static readonly DBBool False = new DBBool(-1); public static readonly DBBool True = new DBBool(1); // Private field that stores –1, 0, 1 for False, Null, True. sbyte value; // Private instance constructor. The value parameter must be –1, 0, or 1. DBBool(int value) { this.value = (sbyte)value; } // Properties to examine the value of a DBBool. Return true if this // DBBool has the given value, false otherwise. public bool IsNull { get { return value == 0; } } public bool IsFalse { get { return value < 0; } } public bool IsTrue { get { return value > 0; } } // Implicit conversion from bool to DBBool. Maps true to DBBool.True and // false to DBBool.False. public static implicit operator DBBool(bool x) { return x ? True : False; } // Explicit conversion from DBBool to bool. Throws an exception if the // given DBBool is Null; otherwise returns true or false. public static explicit operator bool(DBBool x) { if (x.value == 0) throw new InvalidOperationException(); return x.value > 0; } // Equality operator. Returns Null if either operand is Null; otherwise // returns True or False. public static DBBool operator ==(DBBool x, DBBool y) { if (x.value == 0 || y.value == 0) return Null; return x.value == y.value ? True : False; } // Inequality operator. Returns Null if either operand is Null; otherwise // returns True or False. public static DBBool operator !=(DBBool x, DBBool y) { if (x.value == 0 || y.value == 0) return Null; return x.value != y.value ? True : False; } // Logical negation operator. Returns True if the operand is False, Null // if the operand is Null, or False if the operand is True. public static DBBool operator !(DBBool x) { return new DBBool(-x.value); } // Logical AND operator. Returns False if either operand is False, // Null if either operand is Null, otherwise True. public static DBBool operator &(DBBool x, DBBool y) { return new DBBool(x.value < y.value ? x.value : y.value); } // Logical OR operator. Returns True if either operand is True, // Null if either operand is Null, otherwise False. public static DBBool operator |(DBBool x, DBBool y) { return new DBBool(x.value > y.value ? x.value : y.value); } // Definitely true operator. Returns true if the operand is True, false // otherwise. public static bool operator true(DBBool x) { return x.value > 0; } // Definitely false operator. Returns true if the operand is False, false // otherwise. public static bool operator false(DBBool x) { return x.value < 0; } public override bool Equals(object obj) { if (!(obj is DBBool)) return false; return value == ((DBBool)obj).value; } public override int GetHashCode() { return value; } public override string ToString() { if (value > 0) return "DBBool.True"; if (value < 0) return "DBBool.False"; return "DBBool.Null"; } } ``` 重載 **true** 和 **false** 運算符的類型可以用于 [if](https://msdn.microsoft.com/zh-cn/library/5011f09h.aspx)、[do](https://msdn.microsoft.com/zh-cn/library/370s1zax.aspx)、[while](https://msdn.microsoft.com/zh-cn/library/2aeyhxcd.aspx) 和 [for](https://msdn.microsoft.com/zh-cn/library/ch45axte.aspx) 語句以及[條件表達式](https://msdn.microsoft.com/zh-cn/library/ty67wk28.aspx)中的控制表達式。 如果類型定義了 **false** 運算符,則它還必須定義 [true](https://msdn.microsoft.com/zh-cn/library/eahhcxk2.aspx) 運算符。 類型不能直接重載條件邏輯運算符 [&&](https://msdn.microsoft.com/zh-cn/library/2a723cdk.aspx) 和 [||](https://msdn.microsoft.com/zh-cn/library/6373h346.aspx),但通過重載正則邏輯運算符以及運算符 **true** 與 **false** 可以達到同樣的效果。 ## 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) [C# 運算符](https://msdn.microsoft.com/zh-cn/library/6a71f45d.aspx) [true(C# 參考)](https://msdn.microsoft.com/zh-cn/library/eahhcxk2.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>

                              哎呀哎呀视频在线观看