Why use flags+bitmasks rather than a series of booleans?

后端 未结 10 2083
猫巷女王i
猫巷女王i 2021-02-05 03:29

Given a case where I have an object that may be in one or more true/false states, I\'ve always been a little fuzzy on why programmers frequently use flags+bitmasks instead of ju

10条回答
  •  隐瞒了意图╮
    2021-02-05 04:18

    It is for speed and efficiency. Essentially all you are working with is a single int.

    if ((flags & AnchorStyles.Top) == AnchorStyles.Top)
    {
        //Do stuff
    } 
    

提交回复
热议问题