asp.net - Regarding to retrieve values inside the array -


hi creating online quiz in asp.net c#. have 1 form displays testlist in dropdownlist & start button. after clicking 2nd form appears, 2nd form shows 1 label question, radiobuttonlist answers ,next & checkbox review. creating array of random question ids in start button click event of 1stform. when click next button in 2nd form next random question appears, want array of questions checked review. used code arrays of values ( eg.10101) 1 true & 0 false follows want array of question ids checked:

        int[] = (int[])session["values"];//this array of random question ids created in 1st form         int g;         if (chkmark.checked == true)         {             g = 1;         }         else         {             g = 0;         }         int[] chkarray = new int[convert.toint32(session["counter"]) - 1];         int[] temp1 = (int[])session["arrofchk"];         int k, no;          if (temp1 == null)             no = 0;         else             no = temp.length;         (k = 0; k < no; k++)         {        chkarray[k] = temp1[k];         }         chkarray[j] = g; 

personally, use dictionary<int, bool> this.

in key of dictionary, can store random question id, in value of pair, can store checked item state. might take more work refactor it, believe save lot of time in end when want more actions on quiz items.

using dictionary - or @ least chosen collection, think easier right data back.

for example, can work only if positions of both arrays same.

dictionary<int, bool> quizanswers = new dictionary<int, bool>(); // <questionid, checked>  // fill dictionary questions , answers for(int i=0;i<a.length;i++) {   if(temp1.length > i) // make sure don't indexoutofboundsexception   {     quizanswers.add(a[i], temp1[i] == 1);   } }  // answered question in array ( linq ) int[] checkedanswers = (from keyvaluepair<int, bool> pair in quizanswers                         pair.value == true                         select pair.key).toarray<int>(); 

the reason using dictionary here, because think it's neater having 2 separate arrays.

i believe should implement dictionary in quiz, in stead of arrays. if array indexes don't match, or want dynamically add question fixed size array, etc..

it's take consideration. hope out.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -