I've been trying to make this function for the past few hours and hopefully master the use of classes. I have searched vigorously for answers but most of them do not seem to work in my case.
I created a class, public class Car
as well as a constructor & method
static void ReadData()
Now my goal here is to introduce a new instance of Car
and call upon it so that console reads it out. The main problem is that under public void main
it refuses to recognize my ReadData()
method.
Here is my code:
namespace ConsoleApp13
{
class Program
{
public void Main(string[] args)
{
Car crossOver = new Car("BMW", "X4", 2015, "6/23/17");
ReadData(crossOver); // debugger says that ReadData does not exist
{
Console.ReadLine();
}
}
}
public class Car
{
private string make;
private string model;
private int year;
private string whenSold;
public Car(string mk, string mdl, int yr, string sld)
{
make = mk;
model = mdl;
year = yr;
whenSold = sld;
}
static void ReadData(Car Car)
{
Console.WriteLine("Make: " + Car.make);
Console.WriteLine("Model: " + Car.model);
Console.WriteLine("Year: " + Car.year);
Console.WriteLine("Sold at: " + Car.whenSold);
}
}
}
I've tried several different ways of putting static before the scopes but it always ends in some error or the console application immediately exits out without reading the strings