小编Ste*_*ion的帖子

a == b和(a&b)== b之间有什么区别?

我读了一些剧本,似乎很难理解.希望有人能解释为什么第一个:

public static bool ContainsDestroyWholeRowColumn(BonusType bt)
    {
        return (bt & BonusType.DestroyWholeRowColumn) 
            == BonusType.DestroyWholeRowColumn;
    }
Run Code Online (Sandbox Code Playgroud)

为什么不写bt.Equal(BonusType.DestroyWholeRowColumn)bt == BonusType.DestroyWhoeRowColumn?第二:

public bool IsSameType(Shape otherShape)
    {
        if (otherShape == null || !(otherShape is Shape))// check otherShape is not null and it is Shape
            throw new ArgumentException("otherShape");

        return string.Compare(this.Type, (otherShape as Shape).Type) == 0;
    }
Run Code Online (Sandbox Code Playgroud)

如果输入法不是正确的类型.我认为它会立即警觉,为什么他们还需要检查对象的类型最后:

//if we are in the middle of the calculations/loops
            //and we have less than 3 matches, return a random one
            if(row >= Constants.Rows / 2 …
Run Code Online (Sandbox Code Playgroud)

c# boolean-operations

2
推荐指数
1
解决办法
112
查看次数

标签 统计

boolean-operations ×1

c# ×1