Hi
Ive got an error message saying "Object reference not set to an instance of an object." It doesnt make sense to me and the troublshooting tips says to make a new keyword, but since Im new to C# I dont fully understand it. Heres the bit of code thats making the problem. I think I know why the errors coming up because Ive linked two classes together so I might not have done it right. Can someone help me with this please? I just can't seem to figure it out.
class Athletes
{
private Event myEventParticipating;
public Event EventPart
{
get
{
return myEventParticipating;
}
set
{
myEventParticipating = value;
}
}
}
class Event
{
private string myName = "Shotput";
public string Name
{
get
{
return myName;
}
set
{
myName = value;
}
}
}
Console.WriteLine("=====Athlete 1 - Details=====");
Console.WriteLine("");
Console.WriteLine("Enter First Name of Athlete 1:");
athlete1.FirstName = Console.ReadLine();
Console.WriteLine("Enter Last Name of Athlete 1:");
athlete1.LastName = Console.ReadLine();
Console.WriteLine("Enter Address of Athelete 1:");
athlete1.Address = Console.ReadLine();
Console.WriteLine("Enter Phone Number of Athlete 1:");
athlete1.PhoneNumber = Console.ReadLine();//Up to here these lines all work fine
Console.WriteLine("Enter the Event that Athlete 1 is participating in:");
[U][B]athlete1.EventPart.Name = Console.ReadLine();[/B][/U]
Console.WriteLine("Thankyou, Athlete 1 has now been saved.");
The underlined code is the line that comes up with the error that I cant figure it out where Ive gone wrong. Any help will be appreciated, and thanks in advance.