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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:04:49+00:00 2026-05-15T11:04:49+00:00

What is the best way to implement a rank system: here is the code

  • 0

What is the best way to implement a rank system:

here is the code i will use

public class MyRank
{
    private int LevelOneMaxPoints = 100;
    private int LevelTwoMinPoints = 200;
    private int LevelTwoMaxPoints = 299;
    private int LevelThreeMinPoints = 300;
    private int LevelThreeMaxPoints = 399;
    private int LevelFourMinPoints = 400;
    private int LevelFourMaxPoints = 599;
    private int LevelFourPlusMinPoints = 600;
    private int LevelFourPlusMaxPoints = 999;
    private int LevelFiveMinPoints = 1000;
    private int LevelFiveMaxPoints = 1299;
    private int LevelSixMinPoints = 1300;
    private int LevelSixMaxPoints = 2699;
    private int LevelSevenMinPoints = 2700;
    private int LevelSevenMaxPoints = 3999;
    private int LevelEightMinPoints = 4000;
    private int LevelEightMaxPoints = 5499;
    private int LevelEightPlusMinPoints = 5500;
    private int LevelEightPlusMaxPoints = 7499;
    private int LevelNineMinPoints = 7500;
    private int LevelNineMaxPoints = 9999;
    private int LevelTenMinPoints = 10000;

    private string LevelOneName = "Private";
    private string LevelTwoName = "PV2";
    private string LevelThreeName = "Private Fist Class";
    private string LevelFourName = "Specialist";
    private string LevelFourPlusName = "Corporal";
    private string LevelFiveName = "Sergeant";
    //private string LevelSixName = "Staff Sergeant";
    private string LevelSevenName = "Sergeant First Class";
    private string LevelEightName = "Master Sergeant";
    private string LevelEightPlusName = "First Sergeant";
    private string LevelNineName = "Sergeant Major";
    //private string LevelTenName = "Sergeant Major of the Answers";
    private int points = 0;

    public string RankName { get; private set; }
    public MyRank(int points)
    {
        this.points = points;
        RankName = GetRankName();
    }

    private string GetRankName()
    {
        if (points >= Int32.MinValue && points <= LevelOneMaxPoints)
            return LevelOneName;
        else if (points >= LevelTwoMinPoints && points <= LevelTwoMaxPoints)
            return LevelTwoName;
        else if (points >= LevelThreeMinPoints && points <= LevelThreeMaxPoints)
            return LevelThreeName;
        else if (points >= LevelFourMinPoints && points <= LevelFourMaxPoints)
            return LevelFourName;
        else if (points >= LevelFourPlusMinPoints && points <= LevelFourPlusMaxPoints)
            return LevelFourPlusName;
        else if (points >= LevelFiveMinPoints && points <= LevelFiveMaxPoints)
            return LevelFiveName;
        else if (points >= LevelSixMinPoints && points <= LevelSixMaxPoints)
            return LevelFiveName;
        else if (points >= LevelSevenMinPoints && points <= LevelSevenMaxPoints)
            return LevelSevenName;
        else if (points >= LevelEightMinPoints && points <= LevelEightMaxPoints)
            return LevelEightName;
        else if (points >= LevelEightPlusMinPoints && points <= LevelEightPlusMaxPoints)
            return LevelEightPlusName;
        else if (points >= LevelNineMinPoints && points <= LevelNineMaxPoints)
            return LevelNineName;
        else if (points >= LevelNineMinPoints && points <= LevelNineMaxPoints)
            return LevelNineName;
        else if (points >= LevelTenMinPoints)
            return LevelFourName;
        else
            return "No Rank";
    }
}

Do you think this is the most efficient way to do this?

  • 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-05-15T11:04:50+00:00Added an answer on May 15, 2026 at 11:04 am

    I would start by converting your Levels to a single enum. The value of each Enum can be the minimum value, there’s no need to keep track of maximum as you’ll see below.

    public enum Level
    {
        [Description("Private")]
        One = 0,
        [Description("PV2")]
        Two = 200,
        [Description("Private Fist Class")]
        Three = 300,
        ...
        ...
        [Description("Sergeant Major of the Answers")]
        Ten = 10000
    }
    

    Then you can write this to get the name:

    string GetRankName(Level level)
    {
        FieldInfo fieldInfo = level.GetType().GetField(level.ToString());
        DescriptionAttribute[] attributes = (DescriptionAttribute[])fieldInfo.GetCustomAttributes(typeof(DescriptionAttribute), false);
        return (attributes.Length > 0) ? attributes[0].Description : level.ToString();        
    }
    

    and this to get the Level

    Level GetLevel(int points)
    {
        Level level = Level.One;
        foreach(int i in Enum.GetValues(typeof(Level)))
        {
            if (points < i) break;
            level = (Level)i;
        }
        return level;
    } 
    

    then your object members would be:

    public Level Level { get; set; }
    public string RankName { get; set; }
    public MyRank(int points)
    {
        Level = GetLevel(points);
        RankName = GetRankName(Level);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the best way to implement simple pagination? Here is the code im
What is he best way to implement Watermark functionality for a System.Windows.Forms.TextBox in .Net
what could be best way to implement observer pattern when I use 2 programming
What is the best way to implement AdWhirl in iPhone project? - Will we
What is the best way to implement module pattern, while the module code depends
Whats the best way to implement this. I am building application that will be
What is the best way to implement an external module system for a DELPHI
What is the best way to implement GWT Server Side Internationalization? Use native Java
What's the best way to implement Meebo-style floating windows? I'd prefer to use Prototype
What's the best way to implement a WPF plugin system in which each plugin

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.