Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6103533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:44:23+00:00 2026-05-23T13:44:23+00:00

I have some items in database. Each of’em can have many tags, like Browsable,

  • 0

I have some items in database. Each of’em can have many tags, like Browsable, or IsInMenu and so on. A friend of mine suggested to use enums with Flags attribute to create an extensible solution. So, I created a field in DB which takes an integer value, then I created this enum:

 [Flags]
 public enum ItemTags { Browsable = 2, IsInMenu = 4}

Now I’d like to be able to semantically get the list of some items this way:

 public List<Item> GetItems(ItemTags tags)
 {
     /* 
     Code to get data from DB, something like, 
     return repository.GetList(tags);
     */
 }    

and in UI, I’d like to call:

 List<Item> items =  GetItems(ItemTags.Browsable | ItemTags.IsInMneu);

But I don’t get the desired result. Am I going the right way?
By desired result, I mean this:
Values stored in database could be one of the 0, 2, 4, 6 values now. 0 means that the item is not in Menu and also not Browsable. 2 Means that item is Browable, but not in Menu. 4 means item is in Menu, but not Browsable. 6 means item is both Browsable and IsInMenu. Now when I call GetItems function, I don’t get all the items which are browsable, in menu, or both browsable and in menu.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:44:24+00:00Added an answer on May 23, 2026 at 1:44 pm

    use the FlagsAttribute Class

    Indicates that an enumeration can be
    treated as a bit field; that is, a set
    of flags.

    [Flags] 
    public enum ItemTags 
    { 
      Default =0,
      Browsable = 2, 
      IsInMenu = 4,
      All = 6 // Browsable / IsInMenu
    }
    

    More here

    note about enums:

    an Enum by default has an int
    under­neath, and as do all inte­gers
    in C# an enum has a default value of 0
    when first cre­ated. So if 0 is not
    mapped to an enu­mer­a­tion con­stant
    then your enum will be instan­ti­ated
    with an invalid valid

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListBox displaying some items, and in certain modes I stamp a
Right now I have a JSP page that allows to sort some items, when
I have a table with say 1640 items. I set bindingSource.Filter = some filter
Let's say I have some XML like this <channel> <item> <title>This is title 1</title>
I have some business objects which use: Web.Configuration.WebConfigurationManager.AppSettings.Item(SomeSetting) Now that I'm breaking those objects
I have created an item swapper control consisting in two listboxes and some buttons
I have some UI in VB 2005 that looks great in XP Style, but
I have some ASP.NET web services which all share a common helper class they
I have some code for starting a thread on the .NET CF 2.0: ThreadStart
We have some input data that sometimes appears with &nbsp characters on the end.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.