I am stuck at a really stupid mistake.
I want to create an object of the Class Car and store the objects in an array.
So far so good.
But I cant figure out how, or better to say why I cant get any output which makes sence with Console.WriteLine();
I am pretty sure the solution is simple as always, but I cant figure it out on my own.
This is my code
static void Main(string[] args)
{
Car audi = new Car("Audi", "A4", 4); //string Lable, string name, int tires
Car vw = new Car("VW", "Golf", 4);
Car[] carcollection = new Car[] {audi,vw};
Console.WriteLine(carcollection[0]);
}
So is there a way that i can write all the values of an object with Console.WriteLine() without typing in audi.Name, audi.Lable etc?
Console.WriteLine(carcollection[0].Label);or other propertiesToString()method definition on theCarclass if you own/control that.Console.WriteLinewill automatically callToString()for you, so as soon as you define eg.public override string ToString() { return string.Join(" ", Label, Name); }(or similar) on theCarclass,Console.WriteLine(carcollection[0])will automatically produce meaningful results.