So for some reason I seem to be getting a null value on line 43 and im not quite sure why that is. Can someone please explain the issue to me?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace ConsoleApplication9
{
class Program
{
static void Main(string[] args)
{
string myGradesStrg;
string[] gradesStrgArr = new string[50];
int[] gradesArray = new int[50];
string environment = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal) + "\\";
string path = environment + "Grades";
StreamReader gradesFile = new StreamReader((@"C:\Users\Soto\Documents\Grades.txt"));
do
{
myGradesStrg = gradesFile.ReadLine();
if (myGradesStrg != null)
{
Console.WriteLine(myGradesStrg);
int i = 0;
gradesStrgArr[i] = myGradesStrg;
i++;
}
} while (myGradesStrg != null);
Console.ReadLine();
This is line 43:
gradesArray = Array.ConvertAll(gradesStrgArr, int.Parse);
This is the error: An unhandled exception of type 'System.ArgumentNullException' occurred in mscorlib.dll
Additional information: Value cannot be null.
decimal myAvgGrade = MyGradeAverage(gradesArray);
Console.WriteLine("The average of the grades is {0:0}", myAvgGrade);
Console.ReadLine();
}
// The MyGradeAverage Method
// Purpose: Calculates the average of a given array
// Parameters: an integer array list
// Returns: the average of a given array
static decimal MyGradeAverage(int[] myArray)
{
decimal average =(decimal) myArray.Average();
return average;
}
}