public void SaveOnePupilQuestions(string pupilUsername) { StoreDisplay(); // Store the current display UserDatabase userDB = new UserDatabase(); // Create a new instance of a UserDatabase. This can be read from and written to List<TempStoredDisplay> storedDetailsValues = storedDetails[pupilUsername].Values.ToList<TempStoredDisplay>(); // List all of the TempStoredDisplays in the storedDetials Dictionary for (int j = 0; j < storedDetailsValues.Count; j++) // For each display that needs to be saved { TempStoredDisplay tempStoredDisplay = storedDetailsValues[j]; // get the current display that we are saving if (tempStoredDisplay.questions.Count == 0) // If there are no questions in this display { continue; // Skip this display } string[][] questionDetails = new string[4][]; // Create a multi-dimensional array to format the display questionDetails[0] = new string[tempStoredDisplay.questions.Count]; // Set the size of each array in the multi-dimensional array to the number of questions questionDetails[1] = new string[tempStoredDisplay.questions.Count]; questionDetails[2] = new string[tempStoredDisplay.questions.Count]; questionDetails[3] = new string[tempStoredDisplay.questions.Count]; for (int i = 0; i < tempStoredDisplay.questions.Count; i++) // For each question in this display { questionDetails[0][i] = tempStoredDisplay.questions[i].Text; // Add the question to the stored details questionDetails[1][i] = tempStoredDisplay.correctAnswers[i].Text; // Add the correct answer to the stored details questionDetails[2][i] = tempStoredDisplay.wrongAnswers1[i].Text; // Add the wrong answer 1 to the stored details questionDetails[3][i] = tempStoredDisplay.wrongAnswers2[i].Text; // Add the wrong answer 2 to the stored details } userDB.ClearQuestionSet(pupilUsername, storedDetails[pupilUsername].Keys.ToList<string>()[j]); // Clear the question set that we are about to fill userDB.FillQuestionSet(pupilUsername, storedDetails[pupilUsername].Keys.ToList<string>()[j], questionDetails[0], questionDetails[1], questionDetails[2], questionDetails[3]); // Fill the question set with our formatted details } userDB.SaveDatabase(); // Save the database as a file }