I have this code to try to output an already inputted list and ask for a matching grade. The array works, when I check the length of it, it matches the input.
I have declared the string array inside my one class.
static string[] nameArray;
Then I have 2 functions that work in this order:
static void ConvertListToArray()
{
string[] nameArray = names.ToArray();
arrayLength = nameArray.Length;
}
static void AskNameForGrade()
{
for (int i = 0; i < arrayLength; i++)
{
Console.WriteLine($"Please enter grade for {nameArray[i]}");
}
}
The part that gives me the error is the {nameArray[i]}
The error message is
"System.NullReferenceException: 'Object reference not set to an instance of an object.'"
I'm thinking that the array is null, but if I check the size before its equal to the input I put in (ie > 1)
I'm sure this is something simple, but any help would be appreciated.