I am just learning C# using Microsoft Virtual Academy. Here is the code I am working with:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Variables
{
class Program
{
static void Main(string[] args)
{
Car myCar = new Car("BWM", "745li", "Blue", 2006);
printVehicleDetails(myCar);
Console.ReadLine();
}
}
abstract class Vehicle
{
public string Make { get; set; }
public string Model { get; set; }
public int Year { get; set; }
public string Color { get; set; }
public abstract string FormatMe();
public static void printVehicleDetails(Vehicle vehicle)
{
Console.Writeline("Here are the vehicle's details: {0}", vehicle.FormatMe());
}
}
class Car : Vehicle
{
public Car(string make, string model, string color, int year)
{
Make = make;
Model = model
Color = color;
Year = year;
}
public override string FormatMe()
{
return string.Format("{0} - {1} - {2} - {3}",
this.Make,
this.Model,
this.Color,
this.year);
}
}
Anyway, the problem I am having stems from the line printVehicleDetails(myCar)
. When I try to build the project, I get the error "The name 'printVehicleDetails' does not exist in the current context.
I can fix the error by changing the line to Vehicle.printVechicleDetails(myCar)
.
Does anyone know why I have to include Vehicle
in that line?