I'm new in c# and can't find the solution.
I adding two car in an array.
I want to find the biggist car length in Greateslength().
Only I can't select Carlength or others at <--------- CAN'T SELECT
How can I select:
- Carlength
- Widthcar
- CarInfo
- CarBrand
in the Greateslength()method.
abstract class Car
{
abstract int Getperimeter();
}
class Cars
{
public Car[] _Items = new Car[0];
public int Count { get; set; }
public void Add(Car car)
{
Count = Count + 1;
Array.Resize(ref _Items, Count);
_Items[Count - 1] = car;
}
public void Greateslength()
{
foreach (Car element in _Items)
{
int largestCarLength = 0;
if (element. > largestCarLength) <--------- CAN'T SELECT Carlength
{
largestCarLength = element.; < ---------CAN'T SELECT Carlength
Console.WriteLine(element.); < ---------CAN'T SELECT Carlength
< ---------CAN'T SELECT Widthcar
< ---------CAN'T SELECT CarInfo
< ---------CAN'T SELECT CarBrand
}
}
}
}
class VW : Car
{
public VW(int carlength, int widthcar, string carInfo)
{
this.Carlength = carlength;
this.Widthcar = widthcar;
this.CarInfo = carInfo;
this.CarBrand = "VW";
}
private double Carlength { get; set; }
private double Widthcar { get; set; }
private string CarInfo { get; set; }
private string CarBrand { get; set; }
public override double Getperimeter()
{
return Carlength * Widthcar;
}
static void Main(string[] args)
{
VW vw1 = new VW(10, 20, "car 1");
VW vw2 = new VW(22, 11, "car 2");
Cars c1 = new Cars();
c1.Add(vw1);
c1.Add(vw2);
Console.WriteLine("--------------------");
c1.Greateslength();
}