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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:15:47+00:00 2026-05-11T20:15:47+00:00

I have the following as an example: public enum HttpRequestHeader { Accept, AcceptCharset }

  • 0

I have the following as an example:

public enum HttpRequestHeader
{
  Accept,
  AcceptCharset
}

public static class HTTP
{
  public static Hashtable HttpRequestHeaderString
  {
    get
    {
      Hashtable returnHashtable = new Hashtable();
      returnHashtable.Add(HttpRequestHeader.Accept,"Accept");
      returnHashtable.Add(HttpRequestHeader.AcceptCharset,"Accept-Charset");
      return returnHashtable;
    }
  }
}

I will be accessing :

string HttpRequestHeaderString
    = HTTP.HttpRequestHeaderStrings[HttpRequestHeader.Accept]

many times. As this is a static HashTable, is there a better way of providing the same functionality more efficiently?

I understand that I can implement this particular solution using a different type of collection, but if I want to use the HashTable – what options are there for me?

Many thanks in advance SO!

  • 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-11T20:15:47+00:00Added an answer on May 11, 2026 at 8:15 pm

    Do you want callers to be able to mutate the dictionary? If so, having a static one sounds like a very odd idea. If not, you really only need to be able to response to requests for Accept and AcceptCharset, which I’d probably do in a simple switch statement.

    You say you really want to be use a Hashtable – why? What’s the bigger picture here?

    Exposing mutable data structures statically is almost always a bad idea. If you want a helper to build a hashtable with some initial values, then I’d make it a method rather than a property. If you don’t need mutation, I’d write a method to fetch the value for a specific HttpRequestHeader rather than exposing a collection. For example:

    public static class HTTP
    {
        public static string GetHeaderString(HttpRequestHeader header)
        {
            // Use a dictionary here if you want. The API is the important bit
    
            switch (header)
            {
                case HttpRequestHeader.Accept: return "Accept";
                case HttpRequestHeader.AcceptCharset: return "Accept-Charset";
                default: throw new KeyNotFoundException(header.ToString());
            }
        }
    }
    

    Another option would be to have a Java-like enum of headers:

    public sealed class RequestHeader
    {
        public static RequestHeader Accept = new RequestHeader("Accept");
        public static RequestHeader AcceptCharset = 
            new RequestHeader("Accept-Charset");
    
        private readonly string name;
    
        private RequestHeader(string header)
        {
            this. name = name;
        }
    
        public string Name
        {
            get { return name; }
        }
    }
    

    You’d need to do checks against null, but that would be the only invalid value of RequestHeader that you could get. (Enums aren’t range-checked, so someone could easily write ((HttpRequestHeader)-1) in your current code… in other words, it doesn’t fix argument validation anyway.)

    EDIT: In response to the comment, if you’re using C# 3 and want eager initialization (to make life easier) you could write:

    public static class HTTP
    {
        private static readonly Dictionary<HttpRequestHeader, string> Headers =
            new Dictionary<HttpRequestHeader, string>
        {
            ( HttpRequestHeader.Accept, "Accept" ),
            ( HttpRequestHeader.AcceptCharset, "Accept-Charset" )
        };
    
        public static string GetHeaderString(HttpRequestHeader header)
        {
            return Headers[header];
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 171k
  • Answers 171k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Further searches did not lead me to a general solution… May 12, 2026 at 2:15 pm
  • Editorial Team
    Editorial Team added an answer I do not think you can do that. You can… May 12, 2026 at 2:15 pm
  • Editorial Team
    Editorial Team added an answer Maybe I'm not seeing well, but: if ( (!isset($_GET($vars[$i])) or… May 12, 2026 at 2:15 pm

Related Questions

I have an enum type like this as an example: public Enum MyEnum {
how do i switch on an enum which have the flags attribute set (or
I'm building an ASP.NET 3.5 application and would like to expose an enum I
Let's say I have one class Foo that has a bunch of logic in

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.