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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:42:19+00:00 2026-05-11T17:42:19+00:00

I have some code which populates a hashtable with a question as the key

  • 0

I have some code which populates a hashtable with a question as the key and an arraylist of answers as the value.

I want to then print out these values from the hashtable so that it displays the question and corresponding solutions for each individual question in the hashtable.

I know I have done something totally stupid with the foreach loop to printout the hashtable contents, but i’ve been coding for a good few hours straight and I can’t think of the logic to printout my nested arraylist.

Help appreciated greatly.

Here is the code:

//Hashtable Declaration
static Hashtable sourceList = new Hashtable();    

//Class For Storing Question Information
public class QuestionAnswerClass
{
    public string simonQuestion;
    public ArrayList simonAnswer = new ArrayList();
}

//Foreach loop which populates a hashtable with results from
//a linq query that i need to print out.
foreach (var v in linqQueryResult)
        {
            Debug.WriteLine(v.question);
            newques.simonQuestion = v.question;
            //Debug.WriteLine(v.qtype);
            //newques.simonQType = v.qtype;

            foreach (var s in v.solution)
            {
                Debug.WriteLine(s.Answer);
                newques.simonAnswer.Add(s.Answer);
            }
        }          

        sourceList.Add(qTextInput,newques);

//foreach loop to print out contents of hashtable
foreach (string key in sourceList.Keys)
        {
            foreach(string value in sourceList.Values)
            {
                Debug.WriteLine(key);
                Debug.WriteLine(sourceList.Values.ToString());
            }
        }
  • 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-11T17:42:19+00:00Added an answer on May 11, 2026 at 5:42 pm

    As you are using LINQ you are obviously not constrained to framework 1.1, so you should not be using the HashTable and ArrayList classes. You should use the strictly typed generic Dictionary and List classes instead.

    You don’t need a class to keep the question and answers in as you have the Dictionary. The class would only be an extra container with no real purpose.

    //Dictionary declaration
    static Dictionary<string, List<string>> sourceList = new Dictionary<string, List<string>>();
    
    //Foreach loop which populates a Dictionary with results from
    //a linq query that i need to print out.
    foreach (var v in linqQueryResult) {
       List<string> answers = v.solution.Select(s => s.Answer).ToList();
       sourceList.Add(v.question, answers);
    }          
    
    //foreach loop to print out contents of Dictionary
    foreach (KeyValuePair<string, List<string>> item in sourceList) {
       Debug.WriteLine(item.Key);
       foreach(string answer in item.Value) {
          Debug.WriteLine(answer);
       }
    }
    

    If you need the class for some other reason, that could look like below.

    (Note that the question string is both referenced in the class and used as key in the dictionary, but the dictionary key isn’t really used for anything in this code.)

    //Class For Storing Question Information
    public class QuestionAnswers {
    
       public string Question { get; private set; }
       public List<string> Answers { get; private set; }
    
       public QuestionAnswers(string question, IEnumerable<string> answers) {
          Question = question;
          Answers = new List<string>(answers);
       }
    
    }
    
    //Dictionary declaration
    static Dictionary<string, QuestionAnswers> sourceList = new Dictionary<string, QuestionAnswers>();
    
    //Foreach loop which populates a Dictionary with results from
    //a linq query that i need to print out.
    foreach (var v in linqQueryResult) {
       QuestionAnswers qa = new QuestionAnswers(v.question, v.solution.Select(s => s.Answer));
       sourceList.Add(qa.Question, qa);
    }          
    
    //foreach loop to print out contents of Dictionary
    foreach (QustionAnswers qa in sourceList.Values) {
       Debug.WriteLine(qa.Question);
       foreach(string answer in qa.Answers) {
          Debug.WriteLine(answer);
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 190k
  • Answers 190k
  • 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 You don't need data adapter or data set for this… May 12, 2026 at 5:53 pm
  • Editorial Team
    Editorial Team added an answer Answered a similar question yesterday, you may wish to take… May 12, 2026 at 5:53 pm
  • Editorial Team
    Editorial Team added an answer It seems what you want to do is not possible… May 12, 2026 at 5:53 pm

Related Questions

So, let's say I have this code (VB.Net): Sub Main() dim xxx as string
I have a regular control in my code with several items. <mx:List id=myList> <mx:String>Item
I'm in the middle of refactoring some code on my current project, and I'd
I have a for loop as below which populates this data into an array.

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.