Reputation: 320
I have a senario and I am using following enum for the same
[Flags]
enum State
{
None = 0x00,
Added = 0x01,
Edited = 0x02,
Commented = 0x04,
Uncommented = 0x8,
Reordered = 0x16
}
I wanted to get result like this
if Added result will be
Added
if then Edited result will be
Added, Edited
if then Reordered will be
Added, Edited, Reordered
if then Commented will be
Added, Edited, Reordered, Commented
if then Uncommented will be
Added, Edited, Reordered, Commented , Uncommented
if then Commented will be
Added, Edited, Reordered, Commented , Uncommented , Commented
and so on.
Please advice whether I can do the same using any Bitwise
operation.
Upvotes: 0
Views: 265
Reputation: 21917
Two of your requirements make it impossible to use a bitwise flags enum for this purpose.
All of these actions are indistinguishable when using a bitwise flag enum:
Added, Edited, Reordered
Added, Reordered, Edited
Added, Edited, Reordered, Edited
They are all represented as Added | Edited | Reordered
.
As mentioned in comments, you should instead use a List<State>
to represent this data.
Upvotes: 2