C# Foreach Loop Hashtable Issue -


I have some code that gives the key to a hashtable with a question and an array of answers in the form of value In form of.

I want to print these values ​​with a hashtable so that this hashtable shows questions and related solutions for each individual question.

I know that I have completely fooled the foreach loop to print hashtable content, but I am coding for some good hours and I have to argue with my nested array printing Can not think about

Help greatly appreciated.

Here is the code:

  // hashtable declaration static Hashbail source list = new hashtable (); // Class questions to collect information public class questions AnsverClass {public string simone question; Public ArrayList simonAnswer = New ArrayList (); } // Foreach Loop, which displays a result with a Htttable // with a Linux query that I have to print. Forchha (various variants in Linux form) {Debug.WriteLine (v.question); Neuquisison Questionnaire = V. Questian; //Debug.WriteLine (v.qtype); //newques.simonQType = v.qtype; Foreign (Veer in VS.S) {DebugPublishline (SANSR); Newques.simonAnswer.Add (s.Answer); }} SourceList.Add (qTextInput, newques); // External Lap hashtable to print the contents of foreach (string key in sourceList.Keys) {foreach (string value in sourceList.Values) {Debug.WriteLine (key); Debug.WriteLine (sourceList.Values.ToString ()); }}  

As you are using LINQ, you can explicitly structure 1.1 , So you should not use the HashTable and ArrayList classes. Instead you should use strictly typed generic dictionary and list sections.

You do not need a class to answer questions and answers. Dictionary The class will be an additional container with only the actual purpose.

  // Declaration Stable Dictionary & lt; String, list & lt; String & gt; & Gt; SourceList = New Dictionary & lt; String, list & lt; String & gt; & Gt; (); // Foreach Loop, which prints the results from a linq query with a dictionary that I have to print. Foreign language (linqQueryResult in var v) {list & lt; String & gt; Answer = V. solution. Selection (S = & gt; SNSR). Ollist (); SourceList.Add (v.question, answers); } // foreach content from the foreach loop dictionary (KeyWalkerPierter; string; list & lt; string & gt; & gt; in Object source list) {Debug.WriteLine (item.Key); Forex currency (answer to wire in item. Value) {Debug.WriteLine (Answer); }}  

If you need a class for any other reason, it may look like the following.

(Note that the question string is referenced in both classes and used as a key in the dictionary, but the dictionary key is not actually used for anything in this code.) < / P> class questions to collect class questions public class QuestionAnswers {public string question {get; Private set; } Public listing & lt; String & gt; Answer {Get; Private set; } Public Questions Answers (String Questions, IEnumerable & lt; String & gt; Answer) {Question = Question; Answer = new list & lt; String & gt; (answer); }} // Dictionary Static Dictionary & lt; String, questionnaire & gt; SourceList = New Dictionary & lt; String, questionnaire & gt; (); // Foreach Loop, which prints the results from a linq query with a dictionary that I have to print. Foreach (linqQueryResult in var v) {QuestionAnswers qa = New questions Answers (v.question, v.solution.Select (s => s.Answer)); SourceList.Add (qa.Question, qa); } // foreach loop, to print out the contents of the content that goes out of the dictionary (Qation Enars QA Value as the source) {debug. Merge Line (Q. Question); Forex Currency (Answer to string in QA.Enggers) {debug. Merger line (north); }}


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -