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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:44:48+00:00 2026-06-02T17:44:48+00:00

I have a static member in the base class of type: private static Dictionary<string,

  • 0

I have a static member in the base class of type:

private static Dictionary<string, IEnumerable<T>> cachedList;    

This generic member should be available in all derived classes. I’m not sure how to solve it.

EDIT
change member to protected, does not cure my problem.
for more clarification, I used this line of code

    public static void Cache(bool cached)
    {
        string value = typeof(T).ToString();

        if (cachedList == null)
            cachedList = new Dictionary<string, IEnumerable<T>>();
        ///some other things
    }

But every derived class has their own copy of cachedList and every classes returns “true” for the statement of cachedList == null

  • 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-02T17:44:50+00:00Added an answer on June 2, 2026 at 5:44 pm

    Are you asking how to create a static member of a generic class which is shared across all specializations (i.e. all values of T)? If so, read on:

    You can’t do this directly, however you could add an extra base class that your base class inherits from:

    public class NonGenericBase
    {
        private static Dictionary<string, IEnumerable<object>> cachedList = new Dictionary<string, IEnumerable<object>>();
    
        protected static IEnumerable<T> GetCachedList<T>(string key) {
            return (IEnumerable<T>)cachedList[key];
        }
    
        protected static void SetCachedList<T>(string key, IEnumerable<T> value)
            where T : class
        {
            cachedList[key] = (IEnumerable<object>)value;
        }
    }
    

    And then wrap the usage of GetCachedList and SetCachedList in the generic derived class.

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

Sidebar

Related Questions

I have a base class that has a private static member: class Base {
I have this class that has a static member. it is also a base
Is it OK to have a static member variable defined in a base class,
I have a class which have a static member. As I understand, all static
Does a class have to allocate memory for its non-static member functions every time
If you have a class member that is static and public . Would you
I currently have a function: public static Attribute GetAttribute(MemberInfo Member, Type AttributeType) { Object[]
If class inherits base class with static variable member, Will be their only one
Is there anyway to have a sort of virtual static member in C++? For
I intended to create a class which only have static members and static functions.

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.