We help IT Professionals succeed at work.

.NET Enums [Flags] & Bitwise Design Question

Last Modified: 2017-03-23
A hypothetical situation:

I have product features. These features are stored as BITWISE values in the database.

In my back-end code, I have a [Flags] enumerator that lists out all the features with its bitwise value assigned to each item in the enumerator.

This, obviously, gives us great benefit from a coding perspective, and, not to mention, faster I/O and fewer database records.

However, now I want to give someone the ability through a CMS interface, to add a new feature to the features table. Let's call it "Feature7"

So, "Feature7" gets added to the table with the next bit value assigned to it in the database. This is the 7th feature, so this will have a bit value of 64.

But now, the problem is that the [Flags] enum has to be manually updated to include the new feature and its new bit value. Which, doesn't really make the management of Features from CMS "automated"; there's still manual intervention needed from the developers.

So, my question is, using BITWISE, is there a way to make this fully automated without having to have code that generates a new DLL every time features are added to the table, like is suggested here:


Let me know if that makes sense.

Obviously, I know this doesn't need to be done using bits, so I don't need suggestions in that regard.

Thanks in advance!
Watch Question

AndyAinscowFreelance programmer / Consultant

Using bits you could prefill the required enums, call them Feature7, Feature8....FeatureN.

However I usually don't use bitwise operators when the end user may need extra features.  I use a 1:n relation in two tables.  One table has the key value plus a user description.  The other table just stores the key along with the individual items.


Thanks for the reply, Andy. That's the problem: pre-filling the required enum values. I'm just wondering if anyone out there used BITWISE programming and was successful in automating processes.

Yeah, I know the 1:M database design is standard. But the appeal of bitwise is it's faster, it takes up less space, and it makes for really simple C# programming.
AndyAinscowFreelance programmer / Consultant

Don't forget using the 1:n pattern means you don't need to write any code (extremely simple to code), the DB handles data integrity via the relation between the tables.
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)


Thanks, Snarf.  That makes total sense.
AndyAinscowFreelance programmer / Consultant

Hmmm.  :-(

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions