Should “or” work with .Net4 Hasflags: enum.HasFlag(AccessRights.Read | AccessRights.Write)

后端 未结 4 704
自闭症患者
自闭症患者 2020-12-31 06:58

I am trying out the new HasFlags features, and was wondering if the following should work:

enum.HasFlag(AccessRights.Read | AccessRights.Writ

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-31 07:37

    The | operator is bitwise or. It means that if Read is 1 and Write is 2, the value Read | Write is 3 (see its binary representation). So HasFlag returns true only if your enum variable have both Read and Write set.

提交回复
热议问题