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>
Comments
Post a Comment