How do i compare two arrays in c#

  • Thread starter Thread starter Imtiaz383
  • Start date Start date
I

Imtiaz383

Guest
I want to compare between two string arrays. The first string array contains answers from a multiple choice, which consists of only a, b, c and d's in a total of 20 questions. I also have a text file which i call "Answers.txt" which also contains the same strings as array 1. I have copied the answers.txt contents into a new array and now i want to compare with first array. What i mean by compare is, if 3 lines of text does not match with 3 lines of text of array 1 then show me that.

Here is the code below that i have done,

const int size = 20;
string[] multiplechoice = new string[size];
multiplechoice[0]="B";
multiplechoice[1]="D";
multiplechoice[2]="A";
multiplechoice[3]="A";
multiplechoice[4]="C";
multiplechoice[5]="A";
multiplechoice[6]="B";
multiplechoice[7]="A";
multiplechoice[8]="C";
multiplechoice[9]="D";
multiplechoice[10]="B";
multiplechoice[11]="C";
multiplechoice[12]="D";
multiplechoice[13]="A";
multiplechoice[14]="D";
multiplechoice[15]="C";
multiplechoice[16]="C";
multiplechoice[17]="B";
multiplechoice[18]="D";
multiplechoice[19]="A";


string[] choicefromstudents = new string[size];
StreamReader inputfile;
inputfile = File.OpenText("Answers.txt");
int index = 0;
while (index < choicefromstudents.Length && !inputfile.EndOfStream)
choicefromstudents[index] = inputfile.ReadLine();
index++;
inputfile.Close();
for (int index2 = 0; index2 < choicefromstudents.Length; index2++)
for (int index3 = 0; index3 < multiplechoice.Length; index3++)


*******************************************************************

I want to compare array multiplechoice with array choicefromstudents and show which one they got wrong and how many of them they got wrong into a label. How should i do that? Please help.

Continue reading...
 
Back
Top