Code:
namespace DriversLicenceExam
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
LoadKey();
LoadAnswer();
}
private void LoadKey()
{
try
{
const int AnsLgth = 20;
string[] Answers = new string[AnsLgth];
int index = 0;
System.IO.StreamReader inputFile;
inputFile = File.OpenText("DRIVERKEY.txt");
{
Answers[index] = (inputFile.ReadLine());
index++;
}
inputFile.Close();
for (int i = 0; i <= Answers.Length; i++)
{
string value = Answers[i];
listBox1.Items.Add(value);
}
}
catch (Exception)
{
throw;
}
}
I keep getting an error stating 'Value cannot be null. Parameter name; item'
I am relatively new to coding and not sure what this means. Any help or input is appreciated.
The goal of this program is to insert an answer key file, turn it into an array, output it into a listbox, then do the same with answer files, grade the answer files that are submitted by "students" by crossreferencing them with the answer key array, then output the incorrect answers into another listbox.
This is only the first method where I am supposed to input the answer key file then turn it into an array and display it in a listbox.
The answer key text file looks like this:
B
D
A
A
C
A
B
A
C
D
B
C
D
A
D
C
C
B
D
A