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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:50:42+00:00 2026-06-11T10:50:42+00:00

I have a function that assigns values to a dictionary created in c#. After

  • 0

I have a function that assigns values to a dictionary created in c#.
After some computations in the function, the dictionary is compsed of a value and a key.
I need to create a session save this dictionary in this session.
Can anybody help?

  • 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-11T10:50:43+00:00Added an answer on June 11, 2026 at 10:50 am

    Put simply, if you have a Dictionary<string, List<int>> then putting it in the session is not very complicated;

    Dictionary<string, List<int>> myDict = new Dictionary<string, List<int>>();
    HttpContext.Current.Session.Add("MyDictionary", myDict);
    

    If you want to check if the Session already contains your dictionary, and only add it if it doesn’t then:

    if(!HttpContext.Current.Session.ContainsKey("MyDictionary"))
    {
        HttpContext.Current.Session.Add("MyDictionary", myDict);
    }
    

    To get it out, remember that it’s not typed, Session is effectively a dictionary of string, object so you’ll have to cast:

    if(HttpContext.Current.Session.ContainsKey("MyDictionary"))
    {
        Dictionary<string, List<int>> myDict = HttpContext.Current.Session["MyDictionary"] as Dictionary<string, List<int>>;
    }
    

    However, you should also consider what the lifecycle of this object is going to be – Session is not stable in that it has a finite lifetime – it will disappear after a predetermined time of inactivity, for example, so if you want it to hang around for a longer time then you may need to consider alternative strategies.

    There’s a ton of documentation on Session over at MSDN and it’s also a very common topic on Stack Overflow.

    Remember also that, as Session is effectively a Dictionary<String, Object> managed by the .Net Framework and IIS, you could also do:

    Session["MyValues"] = new List<Int32>();
    

    And, of course, on retrieval:

    List<Int32> myValues = Session["MyValues"] as List<Int32>();
    

    Other alternatives include the Cache; if your object is going to be available to all users of the application then this might be a better solution. Please see this answer for more information.

    I’ve also voted to close your question as I believe it’s too localized, but I hope my answer helps you along the way.

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

Sidebar

Related Questions

I have a function that returns two values in a list. Both values need
So I have this code in python that writes some values to a Dictionary
I have a function that gets an int value from the user and assigns
Inside my Controller i have function that runs after user clicks on item, which
I have created some JQuery that on click of specified HTML it then becomes
I have made webpage that uses Ajax to update some values without reloading the
I have some code that creates a variable of some name automatically and assigns
I have a function that I need to pass 4 distinct variables to, and
I've created a function that returns a nested array based in the values and
I have some JavaScript in a page that takes the values passed by a

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.