Sorry if I'm stupid, I'm just a beginner.
I'm trying to make a simple program and it's not really working? If I run the application, but it only says and stops:
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=ConsoleApp1
StackTrace:
at ConsoleApp1.Program.CarMakerMaker(Int32 slot) in C:\Users\Gebruiker\source\repos\ConsoleApp1\ConsoleApp1\Program.cs:line 61
at ConsoleApp1.Program.CarMakerMenu() in C:\Users\Gebruiker\source\repos\ConsoleApp1\ConsoleApp1\Program.cs:line 44
at ConsoleApp1.Program.Main(String[] args) in C:\Users\Gebruiker\source\repos\ConsoleApp1\ConsoleApp1\Program.cs:line 14
Here is the code:
Thanks for your help!
I'm trying to make a simple program and it's not really working? If I run the application, but it only says and stops:
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=ConsoleApp1
StackTrace:
at ConsoleApp1.Program.CarMakerMaker(Int32 slot) in C:\Users\Gebruiker\source\repos\ConsoleApp1\ConsoleApp1\Program.cs:line 61
at ConsoleApp1.Program.CarMakerMenu() in C:\Users\Gebruiker\source\repos\ConsoleApp1\ConsoleApp1\Program.cs:line 44
at ConsoleApp1.Program.Main(String[] args) in C:\Users\Gebruiker\source\repos\ConsoleApp1\ConsoleApp1\Program.cs:line 14
Here is the code:
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
private static bool display = true, slotsChanged = false;
static void Main(string[] args)
{
CarMakerMenu();
}
public static void CarMakerMenu()
{
string[] availible = new string[10];
if (slotsChanged == false)
{
availible[0] = "availible";
availible[1] = "availible";
availible[2] = "availible";
availible[3] = "availible";
availible[4] = "availible";
availible[5] = "availible";
availible[6] = "availible";
availible[7] = "availible";
availible[8] = "availible";
availible[9] = "availible";
}
while (display == true)
{
Console.WriteLine("Welcome to car manager!");
Console.WriteLine("\nPick a slot \n1 {0}, \n2 {1}, \n3 {2}, \n4 {3}, \n5 {4}, \n6 {5}, \n7 {6}, \n8 {7}, \n9 {8}, \n10 {9}\nOr type 0 to exit\n",
availible[0], availible[1], availible[2], availible[3], availible[4], availible[5], availible[6], availible[7], availible[8], availible[9]);
int chosenSlot = Convert.ToInt32(Console.ReadLine());
if (chosenSlot >= 1 || chosenSlot <= 10)
{
slotsChanged = true;
chosenSlot = chosenSlot - 1;
CarMakerMaker(chosenSlot);
chosenSlot = 0;
}
if (chosenSlot == 0)
{
break;
}
else
{
Console.WriteLine("Please enter a valid number");
return;
}
}
}
public static void CarMakerMaker(int slot)
{
Car[] myCar = new Car[10];
myCar[slot].Make = "test";
myCar[slot].Model = "test";
myCar[slot].Year = 1043;
myCar[slot].Color = "test";
Console.WriteLine("{0}\n{1}\n{2}\n{3}", myCar[slot].Make, myCar[slot].Year, myCar[slot].Model, myCar[slot].Color);
Console.ReadLine();
}
}
class Car
{
public string Make { get; set; }
public string Model { get; set; }
public int Year { get; set; }
public string Color { get; set; }
}
}
Thanks for your help!