User-1274246664 posted
Thought I would share this code and ask for suggestions to make this better.
I am grading a quiz and finding what answer(s) were missed. I need to display the question number and the missed answer in lower case as the result.
I have the following:
two sting on is the answers the other is a student selected values there are 54 elements in each string I want to compare the Answer key to the quiz element by element starting at the 4th element to the end.
The results should be the quiz (answered value) and the position or quiz question number so the result should look like this "4x,5a,6b,13b,23b"
[position][Quiz Missed Question]
my code is listed below however I was wondering if LINQ .except or .union or .intersect would be a lot easier, any suggestions?
void Main()
{
var Answer = "17519, , , ,A,B,D,A,D,B,A,C,B,A,C,D,B,D,B,D,D,B,A,D,D,B,B,A,B,A,D,C,B,C,C,B,A,A,C,A,D,B,C,C,A,D,A,D,A,B,B,B,A,B".Split(',').ToArray();
var Quiz = "17519,Test,Person,middle,x,A,B,A,D,B,A,C,B,B,C,D,B,D,B,D,D,B,A,B,D,B,B,A,B,A,D,C,B,C,C,B,A,A,C,A,D,B,C,C,A,D,A,D,A,B,B,B,A,B".Split(',').ToArray();
var MissedQuestionList = gradeExam(Answer,Quiz);
MissedQuestionList.Dump();
}
List<string> gradeExam( string[] answer, string[] quiz)
{
List<string> missedQuestions = new List<string>();
try
{
for( int x = 4; x<=answer.Count()-1;x++)
{
if(answer[x].ToLower() != quiz[x].ToLower())
{
missedQuestions.Add( String.Format("{0}{1},",x, quiz[x].ToLower()));
}
}
return(missedQuestions);
}
catch (Exception ex)
{
throw;
}
}