>> 運算子 (C# 參考)>> Operator (C# Reference)

右移運算子 (>>) 會向其第一個運算元右移第二個運算元所指定的位元數。The right-shift operator (>>) shifts its first operand right by the number of bits specified by its second operand.

備註Remarks

如果第一個運算元是 intuint (32 位元數量),則是由第二個運算元的低序位五位元指定移位計數 (第二個運算元 & 0x1f)。If the first operand is an int or uint (32-bit quantity), the shift count is given by the low-order five bits of the second operand (second operand & 0x1f).

如果第一個運算元是 longulong (64 位元數量),則是由第二個運算元的低序位六位元指定移位計數 (第二個運算元 & 0x3f)。If the first operand is a long or ulong (64-bit quantity), the shift count is given by the low-order six bits of the second operand (second operand & 0x3f).

如果第一個運算元是 intlong,則右移是算術移位 (高序位空位元會設定為正負號位元)。If the first operand is an int or long, the right-shift is an arithmetic shift (high-order empty bits are set to the sign bit). 如果第一個運算元的類型為 uintulong,則右移是邏輯移位 (高序位位元會填上零)。If the first operand is of type uint or ulong, the right-shift is a logical shift (high-order bits are zero-filled).

使用者定義型別可以多載 >> 運算子;第一個運算元的類型必須是使用者定義型別,而第二個運算元的類型必須是 int。如需詳細資訊,請參閱運算子User-defined types can overload the >> operator; the type of the first operand must be the user-defined type, and the type of the second operand must be int. For more information, see operator. 二元運算子多載時,對應的指派運算子 (若有) 也會隱含地多載。When a binary operator is overloaded, the corresponding assignment operator, if any, is also implicitly overloaded.

範例Example

class RightShift
{
    static void Main()
    {
        int i = -1000;
        Console.WriteLine(i >> 3);
    }
}
/*
Output:
-125
*/

請參閱See Also