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

  • Home
  • SEARCH
  • 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 8830747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:09:52+00:00 2026-06-14T08:09:52+00:00

Let me use medical doctors to explain my question. Now doctors have different fields

  • 0

Let me use medical doctors to explain my question. Now doctors have different fields of specialization, like Neurologist=0,Oncologist=1,Cardiologist=2,Gynecologist=3 etc. Let’s say I have a method that takes one of these specialities as an integer and uses it as a parameter to a stored procedure in a database:

DisplaySkills(int speciality)
{
   //create a connection to a database, refer to a stored procedure in the database;
   //send "speciality" as an argument to that stored procedure
}

Now, here I’m sort of in a dilemma as to whether I should have those specialities inside an enum or declare them seperately. From the first sight it feels like I should go with enums because it’s just the case where “one thing can be one of several” but on the other hand it turns out that if I use enums, then I’ll have to cast it to get its internal value. Here’s an example:

enum Speciality
{
  Neurologist=0,
  Oncologist=1,
  Cardiologist=2,
  Gynecologist=3
}
.............
Speciality spec=Speciality.Oncologist;
.............
DisplaySkills(int(spec));

I don’t know, maybe having to cast an enum is a perfectly normal practice and is widely used by programmers, but I thought it would impact the performance (no matter noticeably or not)

  • 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-14T08:09:53+00:00Added an answer on June 14, 2026 at 8:09 am

    I’d go with method DisplaySkills which accepts enum as parameter. Do casting only when call stored procedure.

    Because when is see DisplaySkills(int speciality) then there is no connection with specialties declared in some enum. Maybe I should use it this way?

    DisplaySkills(500);
    

    On the other hand:

    DisplaySkills(Speciality.Neurologist);
    

    It tells me about all possible parameter values. Also I’d change name to DisplaySkillsOf(Speciality.Cardiologist) – looks more like English sentence then. And I’d added guard condition to check that passed value contained in Speciality enum. Otherwise somebody could do this

    DisplaySkills((Speciality)500);
    

    And only inside this method you convert passed enum to int when creating parameter (looks like you are using ADO.NET)

    cmd.Parameters.Add(new SqlParameter("@Speciality", (int)spec));
    

    One more tip about creating guard for your method. You can use generic enum wrapper to check if appropriate value was passed

    if (!Enum<Speciality>.IsDefined(spec))
         throw new ArgumentException("spec");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let me use the following example to explain my question: public string ExampleFunction(string Variable)
I have a list of items implementing an interface. For the question, let's use
I have an IEnumerable <> of Car(here it wont let me use angle brackets
I let my friend use it and now it's gone.
Let's say I have my vision and now my product backlog of items. That
Let's use numbers and letters. My numbers are my primary key. They have always
This is a question regarding queries in mysql. As an example let’s use a
I would like to know how do managers work in Django. Let's use the
Due to my poor English, let me use example to explain my problem. 1,
Long back, android used to have GtalkService that let applications use Gtalk for various

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.