共用方式為


|= 運算子 (C# 參考)

OR 指派運算子。

備註

使用 |= 指派運算子的運算式,例如:

x |= y

相等於

x = x | y

不同的是,x 只被評估了一次。 | 運算子會對整數運算元執行位元邏輯 OR 運算,會對 bool 運算元執行邏輯 OR 運算。

|= 運算子無法直接多載,但使用者定義型別可多載 | 運算子 (請參閱 operator)。

範例

    class MainClass7
    {
        static void Main()
        {
            int a = 0x0c;
            a |= 0x06;
            Console.WriteLine("0x{0:x8}", a);
            bool b = true;
            b |= false;
            Console.WriteLine(b);
        }
    }
    /*
    Output:
    0x0000000e
    True
    */

請參閱

參考

C# 運算子

概念

C# 程式設計手冊

其他資源

C# 參考