I'm trying to use same array multiple times however with different sizes. My aim is to use a single method and then apply the array size when calling the method.
Below is my method:
//print all the excercises and let the user input the weights they lifted
public void PrintExcercises(float[] lift) {
for (int x = 0; x < lift.Length; x++)
{
Console.Write(msg[x]);
lift[x] = float.Parse(Console.ReadLine());
}
}
And here is where I call it:
PrintExcercises(new float[8]);
I get the following error when running the program: "Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object. at GymBuddy.MainProgram.PrintExcercises(Single[] lift) in C:\Users\xxx\OneDrive - xxx\CS Programs\Serious\GymBuddy\GymBuddy\Program.cs:line 136 at GymBuddy.MainProgram.DayD() in C:\Users\xxx\OneDrive - xxx\CS Programs\Serious\GymBuddy\GymBuddy\Program.cs:line 120 at GymBuddy.MainProgram.Workout() in C:\Users\xxx\OneDrive - xxx\CS Programs\Serious\GymBuddy\GymBuddy\Program.cs:line 40 at GymBuddy.MainProgram.Main(String[] args) in C:\Users\xxx\OneDrive - xxx\CS Programs\Serious\GymBuddy\GymBuddy\Program.cs:line 19"
Edit: msg
is an array which holds the various gym excercises performed on a particular day:
string[] msg = new string[] {
"Longbar 3x: ",
"Preacher Bar 3x: ",
"Pull Down Machine 3x: ",
"Cable till exhaustion: ",
"Long Cable 3x: ",
"Behind Head Cable 3x: ",
"Behind Head Dumbells 3x: ",
"Cable till exhaustion: "};