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 8773535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:19:12+00:00 2026-06-13T18:19:12+00:00

I have a class defined as below: public class Category { public int Id

  • 0

I have a class defined as below:

public class Category
{
    public int Id {get; set;}
    public string Name {get; set;}

    //... additional properties ...
}

My database has approximately 10 categories in it, and the set is unlikely to change in the future (though it is possible new categories will be added sporadically). Each category has a number of fields associated with it.

For the most part, other classes are populated with only the category’s Id. I need to perform different actions based on the specific category.

For example:

if (categoryId == 1)
{
    //do something
}
else
{
    //do something else
}

I’m looking to avoid hardcoded values when doing this.

I would typically use an enum for this purpose, but I’m not sure how to structure it in this case, since I already have a class for it. One idea is to create a separate enum called CategoryEnum, but this seems smelly. Another option is to use class constants.

What is the clearest way to compare the category Id against a specific constant value?

  • 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-06-13T18:19:14+00:00Added an answer on June 13, 2026 at 6:19 pm

    Based on Antarr Byrd’s response, it seemed that using class constants made for the clearest code.

    public class Category
    {
        public const int CATEGORY_ONE = 1;
        public const int CATEGORY_TWO = 2;
        //etc.
    
        public int Id {get; set;}
        public string Name {get; set;}
    
        //... additional properties ...
    }
    

    And for comparing:

    if (categoryId == Category.CATEGORY_ONE)
    {
        //do stuff
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple class as defined below: public class Person { int _id;
I have an interface defined as below: public interface TestInterface{ int id { get;
I have two database classes as defined below: public class TopDate { [Key] public
I have a base class, defined as below (I'm also using DevExpress components): public
Lets say I have model inheritance set up in the way defined below. class
I have a Model which has some constants defined, like below: class Order(models.Model): WAITING
I have a class defined as: class Obj { public: int width, height; Obj(int
I have entity like below public abstract class MyBaseClass { public int Id {
If I have a class which has an interface definition like below; public class
I have defined two classes below: public class junk { private BigInteger a =

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.