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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:57:54+00:00 2026-06-01T01:57:54+00:00

I have a website that holds a dictionary of data sets. When a user

  • 0

I have a website that holds a dictionary of data sets. When a user changes pages, and I call the dictionary via its key, I always have to re add all the data sets to the dictionary. It seems kind of redundant. Is there a better way?

classA

public IDictionary<string, DataSet> DataDic { get; private set; }

classB

classA da = new classA();
da.DataDic.Add("Key1",".......");
da.DataDic.Add("Key2",".......");
da.DataDic.Add("Key3",".......");
  • 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-01T01:57:55+00:00Added an answer on June 1, 2026 at 1:57 am

    This is what’s causing it:

    ClassA da = new ClassA();
    

    If you instantiate an entirely new object every time then of course you’re going to have to re-populate that object every time.

    Where do you get the data that you use to populate the object? Does that data change?

    If the data is static, a quick and easy thing to try is to make the field static:

    public static IDictionary<string, DataSet> DataDic { get; set; }
    

    Then you just set it once and it will retain that data. Note that setting it is slightly different. You wouldn’t call an instance of the class, you’d call the class type itself:

    ClassA.DataDic = new Dictionary<string, DataSet>();
    ClassA.DataDic.Add("Key1",".......");
    // ...
    

    This may be a significant design change, depending on how this data is fetched/used/etc. So there could be downsides that we don’t see within the context of this question.

    Another option is to keep it the way it is, but re-factor the populating of the data into the object’s constructor:

    public class ClassA
    {
        public IDictionary<string, DataSet> DataDic { get; private set; }
    
        public ClassA()
        {
            DataDic = new Dictionary<string, DataSet>();
            DataDic.Add("Key1",".......");
            // ...
        }
    }
    

    This outwardly retains the structure of the class, just moves the populating of the data to a single place in code. Note, however, that the data is still being re-populated with each new instance of the class. So if getting the data in the first place is a heavy process and shouldn’t happen more than once, then you might not want to go with this approach.

    There are pros and cons any way you look at it. And a lot of it has to do with factors outside the context of this question.

    (Side note: Notice that I changed the case of your class in this code to begin with a capital letter. This is an idiomatic standard in C#. Note that the code syntax highlighter on this page didn’t highlight your class names as class names. The standard for C# is to expect classes to be capitalized.)

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

Sidebar

Related Questions

I have a website that needs to store two sets of user data into
Maybe a FAQ at this website. I have a TableViewController that holds a form.
I have a <div> that holds a google ad. My website is mostly AJAX
I have a website that plays mp3s in a flash player. If a user
We have a website (foo.com) that does online training. A user logs in, then
I have a website that I've just uploaded onto the Internet. When I browse
We have a website that uses #include file command to roll info into some
I have a website that is perfectely centered aligned. The CSS code works fine.
I have a Website that is really slow and feels really bad when using
I have a website that is deployed between 3 different environments - Dev, Stage,

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.