I am just starting to learn C# in In Visual Studios 2010, and using Bob Tabor's LearnVisualStudio.Net to help. I am on Day 3's homework and wanted to get extra practice in creating classes and defining public and private variables in them and then creating string statements that can be collected into one of the classes for a Console.Write method that the program will display. I feel I have created the public and private variables fine, and even the string statements, but when I go to gather them up and print them, I get an error statement: NullReferenceException was unhandled. I don't know what I am doing wrong. I have pasted the important parts (I think) of each class below.
In the Motorcycles class:
public string GetMotorcycleInfo()
{
string message = "";
message = "A " + Make + " " + Model + " " + EngineSize + " " + "is fast, but ` expensive at "
+ Cost + "!";
return message;
}
in the Bicycles class:
public string GetBikeInfo()
{
string message = "";
message = "A " + Brand + " " + BikeType + NumberOfGears + "bicycle";
return message;
}
In the Mopeds class:
public Motorcycles Cycles
{
get { return motorcycles; }
set { motorcycles = value; }
}
public Bicycles Bikes
{
get { return bicycles; }
set { bicycles = value; }
}
public void DisplayInfo()
{
Console.Write("A " + Cycles.GetMotorcycleInfo());
//Console.Write(" is fast, but expensive.");
Console.Write("A " + Bikes.GetBikeInfo());
//Console.Write(" is slow, but steady.");
Console.Write("But a " + Make + " " + Model + " Moped, with " + Mpg
+ "mpg, and costing only " +
Cost + " is a deal you don't want to pass up!");
}
And, in the Program class:
class Program
{
static void Main(string[] args)
{
Motorcycles myBBBike = new Motorcycles();
myBBBike.Make="Harley Davidson";
myBBBike.Model="Golden Sun";
myBBBike.EngineSize="650 cc";
myBBBike.Cost="$30,000";
Bicycles mySBSBike = new Bicycles();
mySBSBike.Brand = "Schwin";
mySBSBike.NumberOfGears = 10;
mySBSBike.BikeType = "Off Road";
mySBSBike.Price = "$500.00";
Mopeds myMopeds = new Mopeds();
myMopeds.Make = "Renegade";
myMopeds.Model = "TPGS-805";
myMopeds.Mpg = "75 mpg";
myMopeds.Cost = "$599.00";
myMopeds.DisplayInfo();
Console.ReadLine();
}
}
}
Any suggestions would be appreciated. Thank you