2013-05-26 70 views
0

鑑於以下枚舉:位運算枚舉

enum MyEnum 
{ 
    ValueOne = 1, 
    ValueEmpty, 
    ValueTwo = 2, 
    ValueThree = 2, 
    ValueFour = ValueOne | ValueEmpty, 
    ValueFive = ValueTwo | ValueThree 
} 

什麼都在ValueFour和ValueFive元素所涉及的業務,因爲這些都是值我得到?

//Is assigned 3 
var valueOne = (int) MyEnum.ValueFour; 

//Is assigned 2 
var valueTwo = (int)MyEnum.ValueFive; 

由於

回答

5

ValueEmpty是2(ValueOne 1)

valueFour是3(2 | 1)(按位或,0010 OR 0001 = 0011

ValueFive是(2 | 2)這是2(按位或00100010 = 0010