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?
Based on Antarr Byrd’s response, it seemed that using class constants made for the clearest code.
And for comparing: