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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:23:41+00:00 2026-06-07T21:23:41+00:00

I am using a ranges with a method I’m working with, and my manager

  • 0

I am using a ranges with a method I’m working with, and my manager has asked me to use Enum instead of integers, so that instead of having this:

public virtual int MyMethod(int value)
    {
        int result = 0;

        if (value >= 0 && value <= 3333)
        {
            result = 1;
        }
        else if (value >= 3334 && value <= 6666)
        {
            result = 2;
        }
        else if (value >= 6667 && value <= 10000)
        {
            result = 3;
        }
        return result;
    }

I work with something like this:

public virtual int MyMethod(int value)
    {
        int result = 0;

        if (value >= (int)EnumClass.Range.Low.Min && value <= (int)EnumClass.Range.Low.Max)
        {
            result = 1;
        }
        else if (value >= (int)EnumClass.Range.Medium.Min && value <= (int)EnumClass.Range.Medium.Max)
        {
            result = 2;
        }
        else if (value >= (int)EnumClass.Range.High.Min && value <= (int)EnumClass.Range.High.Max)
        {
            result = 3;
        }
        return result;
    }

The EnumClass has other Enum for other methods (i.e. Rating, Priority), so I wished for Range to remain its own variable, kinda like this:

public static enum Rating
    {
        Low = 1,
        Medium,
        High
    };

public static enum[] Range =
    {
        enum Low
        {
            Min = 0,
            Max = 3333
        },

        enum Medium
        {
            Min = 3334,
            Max = 6666
        },

        enum High
        {
            Min = 6667,
            Max = 10000
        }  
    };

I get an error while initializing that array, however, so is there any other way I could achieve this? If possible, I would like to avoid making them three Enum, but if it’s unavoidable I’ll work with this:

public static enum Rating
    {
        Low = 1,
        Medium,
        High
    };
public static enum RangeLow
    {
        Min = 0,
        Max = 3333
    };
public static enum RangeMedium
    {
        Min = 3334,
        Max = 6666
    };
public static enum RangeHigh
    {
        Min = 6667,
        Max = 10000
    };
  • 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-07T21:23:43+00:00Added an answer on June 7, 2026 at 9:23 pm

    You’re being asked (or worse, told) to use a wrench to pound a nail. It will work, but it is unpleasant and this is not an appropriate use for enums, as has been mentioned.

    I would suggest that if this is a common application, having a range defined and checking against it, that you encapsulate the Range in a class (which would probably be just a pair of properties for minimum and maximum, as well as methods for checking values against the range and so forth), and then use that.

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

Sidebar

Related Questions

I'm using the grails findAllBy() method to return a list of Position(s). Position has
As a follow up to the method that collapses overlapping ranges I thought I
I am working on a procedure in Excel using VBA that highlights duplicate rows.
I can take a guess that it has something to do with working with
Is it possible to search on date ranges using Lucene in Java? How do
I have a range of data that I have approximated using a polynomial of
I'm using a JQuery UI slider which has two handles (a.k.a range slider). I
I am trying to re-write a method using TDD. Here is the original method
I'm using ExtJS to make a form that generates a report from the data
I have some strings, entered by users, that may look like this: ++7 7++

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.