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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:13:37+00:00 2026-06-02T17:13:37+00:00

I am keeping a static dictionary to map a simple integer stored in a

  • 0

I am keeping a static dictionary to map a simple integer stored in a database to an enum value.

static Dictionary<long, EModelType> AttributeIdTypeToEModelType = 
   new Dictionary<long, EModelType>()
   {
      {1, EModelType.StatStr},
      {6, EModelType.HistStr},
      {7, EModelType.HistVal}
   };

The great advantage is that I use it to directly get my enum value as the data arrive from the database.

typ = AttributeIdTypeToEModelType[i];

The usage of this system is neat, but it doesn’t look clean to me to have a static dictionary just for this.

I had no chance trying to find a cleaner way to use enumerators and overriding their values.

Any advice?

  • 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-02T17:13:38+00:00Added an answer on June 2, 2026 at 5:13 pm

    You don’t need a Dictionary to cast an int to the appropriate Enum type:

    var type = (EModelType)yourInt;
    

    or using Enum.ToObject:

    var type = Enum.ToObject(typeof(EModelType) , yourInt);
    

    and you can check that it exists with Enum.IsDefined:

    if (! Enum.IsDefined(typeof(EModelType), yourInt)) throw new ArgumentException("Illegal type");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

TL;DR: Which is likely faster: accessing static local variable, accessing variable stored in HttpRuntime.Cache,
public static void loadFilters() throws MalformedURLException { File filtersFile = new File(CONFIG_DIR + /
class CounterDict<TKey> { public Dictionary<TKey, int> _dict = new Dictionary<TKey, int>(); public void Add(TKey
public static <T> List<T> repeat(T contents, int length) { List<T> list = new ArrayList<T>();
I have a method: public static void GetObjects() { using(MyContext context = new MyContext())
I need to create a singleton class without keeping a static method. How can
I have a static Map, which I need to synchronize access to. The map
Consider the following code: class Program { static void Main(string[] args) { new Program().Run(args);
Keeping Util class methods static is a good practice or instance methods are good?
In keeping with the DRY-principle I try to use partials as soon as I

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.