I come up with a problem in creating a program in C#. My problem is a NullReferenceException. I use arrays of lists. I will present below the part of code where I deal with the exceptions:
List<int>[] selected_universities = new List<int> [num_candidates];
int university_code;
for (i = 0; i < num_candidates; i++)
{
Console.WriteLine("Please give the increasing code from 1 to " + num_universities + " in descedant sorted sequence of the universities you would like to enter.");
Console.WriteLine("Press 0 to terminate your list");
for (i = 0; i < num_universities; i++)
{
try
{
Console.WriteLine("Give your code now...");
university_code = Convert.ToInt32(Console.ReadLine());
if (university_code == 0) break;
else selected_universities[i].Add(university_code);
}
catch (NullReferenceException e)
{
Console.WriteLine("The exception: " + e + " has occured!");
}
}
}
List<int>[] temporarily_success_candidates = new List<int>[num_universities];
for (i = 0; i < num_universities; i++)
{
temporarily_success_candidates[i].Add(0);
}