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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:50:44+00:00 2026-05-14T19:50:44+00:00

I have 46 rows of information, 2 columns each row (Code Number, Description). These

  • 0

I have 46 rows of information, 2 columns each row (“Code Number”, “Description”). These codes are returned to the client dependent upon the success or failure of their initial submission request. I do not want to use a database file (csv, sqlite, etc) for the storage/access. The closest type that I can think of for how I want these codes to be shown to the client is the exception class. Correct me if I’m wrong, but from what I can tell enums do not allow strings, though this sort of structure seemed the better option initially based on how it works (e.g. 100 = “missing name in request”).

Thinking about it, creating a class might be the best modus operandi. However I would appreciate more experienced advice or direction and input from those who might have been in a similar situation.

Currently this is what I have:

    class ReturnCode
{
    private int _code;
    private string _message;

    public ReturnCode(int code)
    {
        Code = code;
    }

    public int Code
    {
        get
        {
            return _code;
        }
        set
        {
            _code = value;
            _message = RetrieveMessage(value);
        }
    }

    public string Message { get { return _message; } }

    private string RetrieveMessage(int value)
    {
        string message;

        switch (value)
        {
            case 100:
                message = "Request completed successfuly";
                break;
            case 201:
                message = "Missing name in request.";
                break;
            default:
                message = "Unexpected failure, please email for support";
                break;
        }

        return message;
    }

}
  • 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-14T19:50:45+00:00Added an answer on May 14, 2026 at 7:50 pm

    The best would be both a class and an enumeration. Then you can have more descriptive identifiers than “201”.

    A structure would also work, but they are harder to implement correctly, so you should stick to a class unless you specifically need a structure for some reason.

    You don’t need to store a reference to the message in the class, you can get that when needed in the Message property. A switch is implemented using a hash table (if there are five values or more), so the lookup is very fast.

    public enum ReturnIdentifier {
      Success = 100,
      MissingName = 201;
    }
    
    public class ReturnCode {
    
      public ReturnIdentifier Code { get; private set; }
    
      public ReturnCode(ReturnIdentifier code) {
        Code = code;
      }
    
      public string Message {
        get {
          switch (Code) {
            case ReturnIdentifier.Success:
              return "Request completed successfuly.";
            case ReturnIdentifier.MissingName:
              return "Missing name in request.";
            default:
              return "Unexpected failure, please email for support.";
          }
        }
      }
    
    }
    

    Usage:

    ReturnCode code = new ReturnCode(ReturnIdentifier.Success);
    

    If you get an integer code from somewhere, you can still use it as the enumerator values correspond to the codes:

    int error = 201;
    ReturnCode code = new ReturnCode((ReturnIdentifier)error);
    

    (If the integer code doesn’t correspond to any of the identifiers in the enumeration, it’s still perfectly valid to do the conversion. When getting the Message value, it will end up in the default case as the value doesn’t match any of the other cases.)

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

Sidebar

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.